#include <bits/stdc++.h>
int q[110], s[110], p[110], tmp[110];
bool check(int n) {
  for (int k = 1; k <= n; k++) {
    if (s[k] != p[k]) return false;
  }
  return true;
}
void ch(int n) {
  for (int k = 1; k <= n; k++) {
    tmp[k] = p[q[k]];
  }
  for (int k = 1; k <= n; k++) {
    p[k] = tmp[k];
  }
  return;
}
void hc(int n) {
  for (int k = 1; k <= n; k++) {
    tmp[q[k]] = p[k];
  }
  for (int k = 1; k <= n; k++) {
    p[k] = tmp[k];
  }
  return;
}
int main() {
  int n, m, x = 0, y = 0, k;
  scanf("%d%d", &n, &m);
  for (k = 1; k <= n; k++) {
    scanf("%d", &q[k]);
  }
  bool flag = false;
  for (k = 1; k <= n; k++) {
    scanf("%d", &s[k]);
    if (s[k] != k) flag = true;
  }
  if (!flag) {
    puts("NO");
    return 0;
  }
  for (k = 1; k <= n; k++) p[k] = k;
  for (k = 1; k <= m; k++) {
    ch(n);
    if (check(n)) {
      x = k;
      break;
    }
  }
  for (k = 1; k <= n; k++) p[k] = k;
  for (k = 1; k <= m; k++) {
    hc(n);
    if (check(n)) {
      y = k;
      break;
    }
  }
  if (x == 0 && y == 0) {
    puts("NO");
    return 0;
  }
  if (x == 0) {
    if ((m - y) & 1)
      puts("NO");
    else
      puts("YES");
    return 0;
  }
  if (y == 0) {
    if ((m - x) & 1)
      puts("NO");
    else
      puts("YES");
    return 0;
  }
  if (x == 1 && y == 1) {
    if (m != 1)
      puts("NO");
    else
      puts("YES");
    return 0;
  }
  if (((m - x) & 1) && ((m - y) & 1))
    puts("NO");
  else
    puts("YES");
}
