#include <iostream>
using namespace std;
int main()
{
int n , m;
cin >> n >> m;
int Arr[n] , arr[m];
for ( int i = 0 ; i < n ; i ++ )
{
cin >> Arr[i];
}
for ( int i = 0 ; i < m ; i ++ )
{
cin >> arr[i];
}
int indx1 = 0;
int indx2 = 0;
int counter = 0;
while ( indx2 < m )
{
if ( Arr[indx1] == arr[indx2] )
{
indx2 ++;
}
else
{
counter ++;
if ( counter >= n*m )
{
break;
}
}
if ( indx1 == n - 1 )
{
indx1 = 0;
}
else
{
indx1 ++;
}
}
if ( indx2 == m )
{
cout << "Yes";
}
else
{
cout << "No";
}
return 0;
}