Monotonicity 2

No attempts yetTime limit3sMemory limit512 MB

Problem

For an integer sequence a1,a2,,ana_1, a_2, \ldots, a_n, its monotonicity scheme is the sequence s1,s2,,sn1s_1, s_2, \ldots, s_{n-1} where each sis_i describes how aia_i compares with ai+1a_{i+1}: it is << when ai<ai+1a_i < a_{i+1}, >> when ai>ai+1a_i > a_{i+1}, and == when ai=ai+1a_i = a_{i+1}. For example, the monotonicity scheme of 2,4,3,3,5,32, 4, 3, 3, 5, 3 is <,>,=,<,><, >, =, <, >.

A sequence with monotonicity scheme s1,s2,,sns_1, s_2, \ldots, s_n realizes a scheme s1,s2,,sks'_1, s'_2, \ldots, s'_k when si=s((i1)modk)+1s_i = s'_{((i-1) \bmod k) + 1} for every i=1,2,,ni = 1, 2, \ldots, n. Equivalently, s1,s2,,sns_1, s_2, \ldots, s_n is what you get by writing out s1,s2,,sks'_1, s'_2, \ldots, s'_k over and over and then cutting off a suffix. For instance, 2,4,3,3,5,32, 4, 3, 3, 5, 3 realizes all of <,>,=<, >, = and <,>,=,<,><, >, =, <, > and <,>,=,<,>,<,<,=<, >, =, <, >, <, <, =, among many others.

You are given an integer sequence a1,a2,,ana_1, a_2, \ldots, a_n and a monotonicity scheme s1,s2,,sks_1, s_2, \ldots, s_k. Among all subsequences ai1,ai2,,aima_{i_1}, a_{i_2}, \ldots, a_{i_m} with 1i1<i2<<imn1 \le i_1 < i_2 < \cdots < i_m \le n whose own monotonicity scheme realizes s1,s2,,sks_1, s_2, \ldots, s_k, find the largest possible length mm. A subsequence of a single element (with an empty monotonicity scheme) always realizes the scheme, so the answer is at least 11.

Input

The first line contains two integers nn and kk (1n500,0001 \le n \le 500{,}000, 1k500,0001 \le k \le 500{,}000): the length of the sequence and the length of the monotonicity scheme.

The second line contains nn integers a1,a2,,ana_1, a_2, \ldots, a_n (1ai1,000,0001 \le a_i \le 1{,}000{,}000), separated by single spaces.

The third line contains kk symbols s1,s2,,sks_1, s_2, \ldots, s_k, each one of <<, >>, or ==, separated by single spaces.

Output

Print one integer: the maximum length mm of a subsequence of a1,a2,,ana_1, a_2, \ldots, a_n whose monotonicity scheme realizes s1,s2,,sks_1, s_2, \ldots, s_k.