#include <bits/stdc++.h>
using namespace std;
int main() {
  int N, K;
  scanf("%d%d", &N, &K);
  static int P[100];
  for (int i = 0; i < N; i++) {
    scanf("%d", &P[i]);
    P[i]--;
  }
  static int A[201][100];
  for (int i = 0; i < N; i++) A[K][i] = i;
  for (int i = 0; i < K; i++)
    for (int j = 0; j < N; j++) A[i + K + 1][j] = A[i + K][P[j]];
  for (int i = 0; i < K; i++)
    for (int j = 0; j < N; j++) A[K - i - 1][P[j]] = A[K - i][j];
  static int Q[100];
  for (int i = 0; i < N; i++) {
    scanf("%d", &Q[i]);
    Q[i]--;
  }
  static bool F[201];
  for (int i = 0; i <= K * 2; i++) {
    F[i] = true;
    for (int j = 0; F[i] && j < N; j++) F[i] = (A[i][j] == Q[j]);
  }
  if (F[K]) {
    printf("NO\n");
    return 0;
  }
  int L = K, R = K;
  while (L >= 0 && !F[L]) L--;
  while (R <= K * 2 && !F[R]) R++;
  if (L >= 0 && (~L & 1))
    if (L != K - 1 || !F[K + 1] || K == 1) {
      printf("YES\n");
      return 0;
    }
  if (R <= K * 2 && (~R & 1))
    if (R != K + 1 || !F[K - 1] || K == 1) {
      printf("YES\n");
      return 0;
    }
  printf("NO\n");
  return 0;
}
