For an integer sequence a1,a2,…,an, its monotonicity scheme is the sequence s1,s2,…,sn−1 where each si describes how ai compares with ai+1: it is < when ai<ai+1, > when ai>ai+1, and = when ai=ai+1. For example, the monotonicity scheme of 2,4,3,3,5,3 is <,>,=,<,>.
A sequence with monotonicity scheme s1,s2,…,sn realizes a scheme s1′,s2′,…,sk′ when si=s((i−1)modk)+1′ for every i=1,2,…,n. Equivalently, s1,s2,…,sn is what you get by writing out s1′,s2′,…,sk′ over and over and then cutting off a suffix. For instance, 2,4,3,3,5,3 realizes all of <,>,= and <,>,=,<,> and <,>,=,<,>,<,<,=, among many others.
You are given an integer sequence a1,a2,…,an and a monotonicity scheme s1,s2,…,sk. Among all subsequences ai1,ai2,…,aim with 1≤i1<i2<⋯<im≤n whose own monotonicity scheme realizes s1,s2,…,sk, find the largest possible length m. A subsequence of a single element (with an empty monotonicity scheme) always realizes the scheme, so the answer is at least 1.
The first line contains two integers n and k (1≤n≤500,000, 1≤k≤500,000): the length of the sequence and the length of the monotonicity scheme.
The second line contains n integers a1,a2,…,an (1≤ai≤1,000,000), separated by single spaces.
The third line contains k symbols s1,s2,…,sk, each one of <, >, or =, separated by single spaces.
Print one integer: the maximum length m of a subsequence of a1,a2,…,an whose monotonicity scheme realizes s1,s2,…,sk.