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])) # Check if A and B are permutations if sorted(A) != sorted(B): print("No") return if k <= 2: print("Yes") return elif k > N: if A == B: print("Yes") else: print("No") return else: # Check if N >= 2*k -2 if N >= 2*k - 2: print("Yes") return else: # Check first k-1 elements and last k-1 elements same = True # Check first k-1 elements for i in range(k-1): if A[i] != B[i]: same = False break if same: # Check last k-1 elements for i in range(N - (k-1), N): if A[i] != B[i]: same = False break if same: print("Yes") else: print("No") return if __name__ == "__main__": main()