import java.util.*;
import java.io.*;
public class Main{
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
String[] nums = br.readLine().trim().split(" ");
int n = Integer.parseInt(nums[0]);
int m = Integer.parseInt(nums[1]);
String s1 = br.readLine();
String s2 = br.readLine();
boolean res = isRotationWords(s1, s2);
if(res){
System.out.println("YES");
}else{
System.out.println("NO");
}
}
public static boolean isRotationWords(String s1, String s2){
if(s1 == null || s2 == null || s1.length() != s2.length())
return false;
String s = s1 + s1;
return s.contains(s2);
}
}