#include <bits/stdc++.h>
using namespace std;
const int MAXN = 101;
int N, M;
int to[MAXN], q[MAXN], b[MAXN][MAXN], c[MAXN];
void gao(int from[], int goal[]) {
  for (int i = 1; i <= N; ++i) {
    goal[i] = from[q[i]];
  }
}
void gao2(int from[], int goal[]) {
  for (int i = 1; i <= N; ++i) {
    goal[q[i]] = from[i];
  }
}
bool isSame(int a[], int b[]) {
  for (int i = 1; i <= N; ++i) {
    if (a[i] != b[i]) {
      return false;
    }
  }
  return true;
}
bool oo;
int main() {
  while (~scanf("%d%d", &N, &M)) {
    for (int i = 1; i <= N; ++i) {
      b[0][i] = i;
      scanf("%d", &q[i]);
    }
    for (int i = 1; i <= N; ++i) {
      scanf("%d", &to[i]);
    }
    if (isSame(b[0], to)) {
      goto NO;
    }
    gao2(b[0], c);
    oo = isSame(c, to);
    for (int i = 1; i <= M; ++i) {
      gao(b[i - 1], b[i]);
      if (isSame(b[i], to)) {
        if (M == 1 || ((M - i) % 2 == 0 && (i > 1 || !oo))) {
          printf("YES\n");
          goto AGG;
        } else {
          goto AG;
        }
      }
    }
  AG:
    gao(b[0], c);
    oo = isSame(c, to);
    for (int i = 1; i <= M; ++i) {
      gao2(b[i - 1], b[i]);
      if (isSame(b[i], to)) {
        if (M == 1 || ((M - i) % 2 == 0 && (i > 1 || !oo))) {
          printf("YES\n");
          goto AGG;
        } else {
          goto NO;
        }
      }
    }
  NO:
    printf("NO\n");
  AGG:;
  }
  return 0;
}
