#include <iostream>
using namespace std;
int main()
{
int n , m;
cin >> n >> m;
int arr1[n] , arr2[m];
for ( int i = 0 ; i < n ; i ++ )
{
cin >> arr1[i];
}
for ( int i = 0 ; i < m ; i ++ )
{
cin >> arr2[i];
}
int i = 0;
int j = 0;
int counter = 0;
int polo = 0;
while ( i < n )
{
if ( i == n - 1 )
{
i = 0;
}
else
{
i ++;
}
if ( arr1[i] == arr2[j] && j < m )
{
j ++;
counter ++;
}
if ( (polo / n ) > counter || j == m )
{
break;
}
polo ++;
}
if ( counter == m )
{
cout << "Yes";
}
else
{
cout << "No";
}
return 0;
}