#include <bits/stdc++.h>
int q[110], n, p[110], np[110], ans[110];
int is_same() {
  for (int i = 1; i <= n; i++)
    if (p[i] != ans[i]) return 0;
  return 1;
}
int main() {
  int i, j, k, hcount = -1, tcount = -1;
  scanf("%d%d", &n, &k);
  for (i = 1; i <= n; i++) scanf("%d", &q[i]);
  for (i = 1; i <= n; i++) scanf("%d", &ans[i]);
  for (i = 1; i <= n; i++) p[i] = i;
  if (is_same()) {
    printf("NO");
    return 0;
  }
  for (j = 1; j <= k; j++) {
    for (i = 1; i <= n; i++) np[i] = p[q[i]];
    for (i = 1; i <= n; i++) p[i] = np[i];
    if (is_same()) {
      hcount = j;
      break;
    }
  }
  for (i = 1; i <= n; i++) p[i] = i;
  for (j = 1; j <= k; j++) {
    for (i = 1; i <= n; i++) np[q[i]] = p[i];
    for (i = 1; i <= n; i++) p[i] = np[i];
    if (is_same()) {
      tcount = j;
      break;
    }
  }
  if ((tcount == -1 && hcount == -1) ||
      (tcount == 1 && hcount == 1 && k != 1)) {
    printf("NO");
    return 0;
  }
  if (((k - tcount) % 2 == 0 && tcount != -1) ||
      ((k - hcount) % 2 == 0 && hcount != -1))
    printf("YES");
  else
    printf("NO");
  return 0;
}
