#include <bits/stdc++.h>
using namespace std;
const int N = 105;
int n, k, p[N], s[N], q[N], nxt[N];
bool eq() {
  for (int i = 1; i <= n; i++)
    if (p[i] != s[i]) return false;
  return true;
}
void forward() {
  for (int i = 1; i <= n; i++) nxt[i] = p[q[i]];
  for (int i = 1; i <= n; i++) p[i] = nxt[i];
}
void backward() {
  for (int i = 1; i <= n; i++) nxt[q[i]] = p[i];
  for (int i = 1; i <= n; i++) p[i] = nxt[i];
}
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 (eq()) {
    puts("NO");
    return 0;
  }
  bool ok;
  forward();
  ok = (!eq());
  backward();
  backward();
  ok |= (!eq());
  forward();
  int dist1, dist2;
  dist1 = dist2 = -1;
  for (int i = 1; i <= k; i++) {
    forward();
    if (eq()) {
      dist1 = i;
      break;
    }
  }
  for (int i = 1; i <= (dist1 == -1 ? k : dist1); i++) backward();
  for (int i = 1; i <= k; i++) {
    backward();
    if (eq()) {
      dist2 = i;
      break;
    }
  }
  if (dist1 == k || dist2 == k) {
    puts("YES");
    return 0;
  }
  if (ok && (((k - dist1) % 2 == 0 && dist1 > 0) ||
             ((k - dist2) % 2 == 0 && dist2 > 0))) {
    puts("YES");
    return 0;
  }
  puts("NO");
  return 0;
}
