#include <bits/stdc++.h>
inline int getint() {
  int x = 0, p = 1;
  char c = getchar();
  while (c <= 32) c = getchar();
  if (c == 45) p = -p, c = getchar();
  while (c > 32) x = x * 10 + c - 48, c = getchar();
  return x * p;
}
using namespace std;
const int N = 110;
int a[N], p[N], b[N], s[N], n, m, mx, my;
void init() {
  for (int i = 1; i <= n; i++) {
    a[i] = i;
  }
}
bool check() {
  for (int(i) = 0; (i) < (n); (i)++) {
    if (a[i + 1] != s[i + 1]) return false;
  }
  return true;
}
bool func() {
  if (!mx || !my) return false;
  if (mx == m) return true;
  if (my == m) return true;
  if (mx < m && (m - mx) % 2 == 0 && (mx >= 2 || my >= 2)) return true;
  if (my < m && (m - my) % 2 == 0 && (mx >= 2 || my >= 2)) return true;
  return false;
}
int main() {
  n = getint();
  m = getint();
  for (int i = 1; i <= n; i++) {
    p[i] = getint();
  }
  for (int i = 1; i <= n; i++) {
    s[i] = getint();
  }
  mx = N;
  my = N;
  init();
  for (int(j) = 0; (j) < (N); (j)++) {
    if (check()) {
      mx = min(mx, j);
    }
    for (int i = 1; i <= n; i++) {
      b[i] = a[p[i]];
    }
    for (int i = 1; i <= n; i++) {
      a[i] = b[i];
    }
  }
  init();
  for (int(j) = 0; (j) < (N); (j)++) {
    if (check()) {
      my = min(my, j);
    }
    for (int i = 1; i <= n; i++) {
      b[p[i]] = a[i];
    }
    for (int i = 1; i <= n; i++) {
      a[i] = b[i];
    }
  }
  if (func()) {
    printf("YES\n");
  } else {
    printf("NO\n");
  }
  return 0;
}
