from collections import Counter def main(): import sys input = sys.stdin.read().split() idx = 0 N = int(input[idx]) idx += 1 k = int(input[idx]) idx += 1 A = list(map(int, input[idx:idx+N])) idx += N B = list(map(int, input[idx:idx+N])) if A == B: print("Yes") return if k == 1: print("No") return if k > N: print("No") return if k == N: reversed_A = A[::-1] if B == reversed_A: print("Yes") else: print("No") return # Check if elements are the same if Counter(A) == Counter(B): print("Yes") else: print("No") if __name__ == "__main__": main()