#include <iostream>
using namespace std;
int main()
{
int n, m;
cin >> n >> m;
int big[n];
int small[m];
for (int i = 0; i < n; i++)
cin >> big[i];
for (int i = 0; i < m; i++)
cin >> small[i];
bool flag = true;
for (int i = 0; i < n; i++)
{
flag = true;
for (int j = 0; j < m; j++)
{
if (big[(i + j) % n] != small[j])
{
flag = false;
break;
}
}
if (flag)
break;
}
if (flag)
cout << "YES";
else
cout << "NO";
return 0;
}