#include <bits/stdc++.h>
const int N = 105;
int n, k, a[N], b[N], q[N], s[N], loc[N];
int check() {
  for (int i = 1; i <= n; i++) a[i] = i;
  for (int t = 0; t <= k; t++) {
    bool ok = 1;
    for (int i = 1; i <= n; i++) ok &= a[i] == s[i];
    if (ok) return t;
    for (int i = 1; i <= n; i++) {
      b[i] = a[q[i]];
    }
    for (int i = 1; i <= n; i++) a[i] = b[i];
  }
  return N;
}
bool calc(int x, int y) {
  if (x == N) return 0;
  if ((k & 1) != (x & 1)) return 0;
  if (x == 1 && k > 1 && y >= -1) return 0;
  if (x == 0 && k > 1 && y >= -1) return 0;
  return 1;
}
int main() {
  scanf("%d%d", &n, &k);
  for (int i = 1; i <= n; i++) scanf("%d", &q[i]);
  for (int i = 1; i <= n; i++) scanf("%d", &s[i]);
  int x = check();
  for (int i = 1; i <= n; i++) loc[q[i]] = i;
  for (int i = 1; i <= n; i++) q[i] = loc[i];
  int y = check();
  puts(calc(x, -y) || calc(y, -x) ? "YES" : "NO");
  scanf("\n");
}
