1 1
1
2
 6 3
1 2 3 4 5 6
3 5 1
 5 5
5 6 3 2 1
4 3 1 5 6
 1 1
1
1
 10 10
1 2 3 4 5 6 7 8 9 10
6 7 8 9 10 1 2 3 4 5
 1 2
1
1 2
 10 10
9 12 15 2 4 14 1 5 6 13
12 11 13 1 4 3 8 2 14 15
 9 9
1 2 3 4 5 6 7 8 9
7 8 9 1 2 4 5 6 3
 5 5
9 2 5 1 3
1 7 2 3 9

0
 1
 4
 1
 10
 1
 3
 8
 3

#include <fstream>
#include <iostream>
#include <vector>
#include <map>
#include <algorithm>
#include <deque>
#define _USE_MATH_DEFINES
#include <math.h>
#include <string>
using namespace std;
void main()
{
	ios_base::sync_with_stdio(false);
	//ifstream cin("input.txt");
	__int64 n,m;
	vector <int> a,b;
	b.resize(2000000,-1);
	cin>>n>>m;
	a.resize(2*n);
	for (int i=0;i<n;i++)
	{
		cin>>a[i];
		a[i]--;
		a[n+i]=a[i];
	}
	__int64 q;
	for (int i=0;i<m;i++)
	{
		cin>>q;
		q--;
		b[q]=i;
	}
	__int64 res=0;
	__int64 l=-1;
	deque <__int64> qq;
	for (int r=0;r<2*n;r++)
	{
		if (b[a[r]]==-1)
		{
			l=-1;
			qq.clear();
			continue;
		}
		q=b[a[r]];
		if (!qq.empty())
		{
			while (q<qq.back()) q+=m;
			while (!qq.empty()&&(q-qq.front()>m))
				qq.pop_front();
		}
		qq.push_back(q);
		res=max<__int64> (res,qq.size());
	}
	cout<<res;
}