Polycarpus enjoys studying Berland hieroglyphs. Once Polycarp got hold of two ancient Berland pictures, on each of which was drawn a circle of hieroglyphs. We know that no hieroglyph occurs twice in either the first or the second circle (but in can occur once in each of them).

Polycarpus wants to save these pictures on his laptop, but the problem is, laptops do not allow to write hieroglyphs circles. So Polycarp had to break each circle and write down all of its hieroglyphs in a clockwise order in one line. A line obtained from the first circle will be called *a*, and the line obtained from the second one will be called *b*.

There are quite many ways to break hieroglyphic circles, so Polycarpus chooses the method, that makes the length of the largest substring of string *a*, which occurs as a subsequence in string *b*, maximum.

Help Polycarpus — find the maximum possible length of the desired substring (subsequence) if the first and the second circles are broken optimally.

The length of string *s* is the number of characters in it. If we denote the length of string *s* as |*s*|, we can write the string as *s* = *s*<sub class="lower-index">1</sub>*s*<sub class="lower-index">2</sub>... *s*<sub class="lower-index">|*s*|</sub>.

A substring of *s* is a non-empty string *x* = *s*[*a*... *b*] = *s*<sub class="lower-index">*a*</sub>*s*<sub class="lower-index">*a* + 1</sub>... *s*<sub class="lower-index">*b*</sub> (1 ≤ *a* ≤ *b* ≤ |*s*|). For example, "code" and "force" are substrings of "codeforces", while "coders" is not. 

A subsequence of *s* is a non-empty string *y* = *s*[*p*<sub class="lower-index">1</sub>*p*<sub class="lower-index">2</sub>... *p*<sub class="lower-index">|*y*|</sub>] = *s*<sub class="lower-index">*p*<sub class="lower-index">1</sub></sub>*s*<sub class="lower-index">*p*<sub class="lower-index">2</sub></sub>... *s*<sub class="lower-index">*p*<sub class="lower-index">|*y*|</sub></sub> (1 ≤ *p*<sub class="lower-index">1</sub> &lt; *p*<sub class="lower-index">2</sub> &lt; ... &lt; *p*<sub class="lower-index">|*y*|</sub> ≤ |*s*|). For example, "coders" is a subsequence of "codeforces".
The first line contains two integers *l*<sub class="lower-index">*a*</sub> and *l*<sub class="lower-index">*b*</sub> (1 ≤ *l*<sub class="lower-index">*a*</sub>, *l*<sub class="lower-index">*b*</sub> ≤ 1000000) — the number of hieroglyphs in the first and second circles, respectively.

Below, due to difficulties with encoding of Berland hieroglyphs, they are given as integers from 1 to 10<sup class="upper-index">6</sup>.

The second line contains *l*<sub class="lower-index">*a*</sub> integers — the hieroglyphs in the first picture, in the clockwise order, starting with one of them.

The third line contains *l*<sub class="lower-index">*b*</sub> integers — the hieroglyphs in the second picture, in the clockwise order, starting with one of them.

It is guaranteed that the first circle doesn't contain a hieroglyph, which occurs twice. The second circle also has this property.
import fileinput


lines = []
for line in fileinput.input():
    lines.append([int(x) for x in line.split()])

n,m = lines[0]
a = lines[1]
b = lines[2]
# length of the largest substring a that occurs as a subsequence in string b maximum

# noe hieroglyph occurs twice in a or twice in b

# Brute force

# For every rotation of a
#   For every rotation of b
# 
#       For substring of a
#           For subseq of b
#               if substr == subseq:
#                   res.append(len(substr))

# If substring in a of len(n) exists in subseq of b then 
#       Also exists substring of len(n) - 1


# How many size substrins in a:  len(a) - size
# How many size subseqs in a: comb(len(a), size)


# If maximum substring exists in one rotation then the rotation which starts with
# the substring also fulfills the optimality props for a 


# Fast way of checkin if substr of a in subseq b
# Two pointers 

# Same thing for the second circle

# What are my redundanceis 
#   For every r1 i start from scratch for every r2 can i do something about that?
#       Suppose I know the matched substr - subseq  from previous rotation
#           can i use that? the target substr is the same 
#   For every r2 I start from scratch for every r1.
#       Suppose I know the max substr of size n for roataion r`
#           is that substr a tail of the solution?
#           if yes rotating right gives a better solution
#           until we reach a local optimum
#
#           rotation r' + 1 and r' -1 will have at least size n - 1
#           how is this useful?  u just ruin the solution

# Statistics has ruined me

# Lessons leanred -> never try brute force from start

def idx(arr, i):
    "rotated index"
    return arr[i % len(arr)]

def rot(i, x, arr):
    "rotate anti-clockwise index i for array arr by x"
    return i + x % len(arr)

res = []
mapping = {}

for i, v in enumerate(b):
    mapping[v] = i

for r1 in range(len(a)):
    val = idx(a,r1)
    if val not in mapping:
        continue
    r2 = mapping[val]

    i =0 
    j = 0
    cl = 0
    while i < len(a) and j < len(b):
        if idx(a, i +r1) == idx(b, j +r2):
            i +=1 
            j +=1
            cl +=1
        else:
            j+=1
    res.append(cl)

print(max(res))

# ret max(res)

