#include <bits/stdc++.h>
using namespace std;
int n, k, now;
int p[105], q[105], s[105];
int ans1, ans2;
void imp1() {
  int now[105];
  for (int i = 1; i <= n; i++) now[i] = p[i];
  for (int i = 1; i <= n; i++) p[i] = now[q[i]];
}
void imp2() {
  int now[105];
  for (int i = 1; i <= n; i++) now[i] = p[i];
  for (int i = 1; i <= n; i++) p[q[i]] = now[i];
}
bool check(int* x, int* y) {
  bool flag = 1;
  for (int j = 1; j <= n; j++)
    if (x[j] != y[j]) {
      flag = 0;
      break;
    }
  return flag;
}
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]);
  for (int i = 1; i <= n; i++) p[i] = i;
  if (check(p, s)) {
    puts("NO");
    return 0;
  }
  for (now = 1; now <= k + 1; now++) {
    if (check(p, s)) break;
    imp1();
  }
  for (int i = 1; i <= n; i++) p[i] = i;
  ans1 = now - 1;
  for (now = 1; now <= k + 1; now++) {
    if (check(p, s)) break;
    imp2();
  }
  ans2 = now - 1;
  if (ans1 == 1 && ans2 == 1 && k != 1)
    puts("NO");
  else if ((k - ans1) % 2 == 0 || (k - ans2) % 2 == 0)
    puts("YES");
  else
    puts("NO");
  return 0;
}
