#include <bits/stdc++.h>
using namespace std;
bool Check(int M[], int Now[], int N) {
  for (int i = 1; i <= N; i++) {
    if (M[i] != Now[i]) return false;
  }
  return true;
}
int main() {
  int N, K, Q[105], M[105], Now[105];
  scanf("%d %d", &N, &K);
  for (int i = 1; i <= N; i++) {
    scanf("%d", &Q[i]);
  }
  for (int i = 1; i <= N; i++) {
    scanf("%d", &M[i]);
  }
  for (int i = 1; i <= N; i++) {
    Now[i] = i;
  }
  if (Check(M, Now, N) == true) {
    printf("NO\n");
    return 0;
  }
  int h = -1, t = -1;
  for (int i = 0; i < K; i++) {
    int tmp[105];
    for (int j = 1; j <= N; j++) {
      tmp[j] = Now[Q[j]];
    }
    for (int j = 1; j <= N; j++) Now[j] = tmp[j];
    if (Check(M, Now, N) == true) {
      h = i + 1;
      break;
    }
  }
  for (int i = 1; i <= N; i++) {
    Now[i] = i;
  }
  for (int i = 0; i < K; i++) {
    int tmp[105];
    for (int j = 1; j <= N; j++) {
      tmp[Q[j]] = Now[j];
    }
    for (int j = 1; j <= N; j++) {
      Now[j] = tmp[j];
    }
    if (Check(M, Now, N) == true) {
      t = i + 1;
      break;
    }
  }
  if (t == 1 && h == 1 && K != 1) {
    printf("NO\n");
    return 0;
  }
  if (t != -1 && ((K - t) % 2 == 0)) {
    printf("YES\n");
    return 0;
  }
  if (h != -1 && ((K - h) % 2 == 0)) {
    printf("YES\n");
    return 0;
  }
  printf("NO\n");
  return 0;
}
