#include <bits/stdc++.h>
using namespace std;
int n, q[110], cur[110], nxt[110];
void proc() {
  for (int i = 1; i <= n; i++) nxt[i] = cur[q[i]];
  for (int i = 1; i <= n; i++) cur[i] = nxt[i];
}
void proc2() {
  for (int i = 1; i <= n; i++) nxt[q[i]] = cur[i];
  for (int i = 1; i <= n; i++) cur[i] = nxt[i];
}
int des[110];
bool check() {
  for (int i = 1; i <= n; i++)
    if (cur[i] != des[i]) return false;
  return true;
}
int k;
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", &des[i]);
  int L = k + 1, R = k + 1;
  for (int i = 1; i <= n; i++) cur[i] = i;
  if (check()) {
    puts("NO");
    return 0;
  }
  for (int i = 1; i <= k; i++) {
    proc();
    if (check()) {
      R = i;
      break;
    }
  }
  for (int i = 1; i <= n; i++) cur[i] = i;
  for (int i = 1; i <= k; i++) {
    proc2();
    if (check()) {
      L = i;
      break;
    }
  }
  if (L > k && R > k) {
    puts("NO");
  } else if (L > k) {
    puts((R & 1) == (k & 1) ? "YES" : "NO");
  } else if (R > k) {
    puts((L & 1) == (k & 1) ? "YES" : "NO");
  } else if (L == k || R == k) {
    puts("YES");
  } else if (L == 1 && R == 1) {
    puts("NO");
  } else {
    puts(((L & 1) == (k & 1) || (R & 1) == (k & 1)) ? "YES" : "NO");
  }
  return 0;
}
