#include <bits/stdc++.h>
int a[2][110], q[110], b[110], flag;
int n;
int same(int *x, int *y) {
  int i;
  for (i = 1; i <= n; ++i)
    if (x[i] != y[i]) return 0;
  return 1;
}
int ok;
int main() {
  int k, i, j, p, pp;
  scanf("%d%d", &n, &k);
  for (j = 1; j <= n; ++j) a[0][j] = j;
  for (i = 1; i <= n; ++i) scanf("%d", &q[i]);
  for (i = 1; i <= n; ++i) scanf("%d", &b[i]);
  if (same(a[0], b)) {
    printf("NO\n");
    return 0;
  }
  p = pp = k + 1;
  for (i = 1; i <= k; ++i) {
    for (j = 1; j <= n; ++j) a[!flag][j] = a[flag][q[j]];
    flag = !flag;
    if (same(a[flag], b)) {
      p = i;
      break;
    }
  }
  for (j = 1; j <= n; ++j) a[0][j] = j;
  flag = 0;
  for (i = 1; i <= k; ++i) {
    for (j = 1; j <= n; ++j) a[!flag][q[j]] = a[flag][j];
    flag = !flag;
    if (same(a[flag], b)) {
      pp = i;
      break;
    }
  }
  if (p == k + 1 && pp == k + 1) {
    printf("NO\n");
    return 0;
  }
  if (p == k || pp == k)
    ok = 1;
  else if (p + pp > 2) {
    if (p < k && (p & 1) == (k & 1) || pp < k && (pp & 1) == (k & 1)) ok = 1;
  }
  printf("%s\n", ok ? "YES" : "NO");
  return 0;
}
