#include <bits/stdc++.h>
long long read() {
  long long x = 0, f = 1;
  char c = getchar();
  while (c < '0' || c > '9') {
    if (c == '-') f = -1;
    c = getchar();
  }
  while (c >= '0' && c <= '9') {
    x = x * 10 + c - '0';
    c = getchar();
  }
  return f * x;
}
long long max(long long a, long long b) { return a > b ? a : b; }
void umax(long long& a, long long t) {
  if (t > a) a = t;
}
const long long INF = 1ll << 58;
long long a[2011], t[2011], q[2011], begin[2011], end[2011];
long long n, k;
long long check_rev(long long* s) {
  for (long long i = 1; i <= n; ++i) a[i] = i;
  for (long long x = 1; x <= k; ++x) {
    for (long long i = 1; i <= n; ++i) t[q[i]] = a[i];
    bool fail = 0;
    for (long long i = 1; i <= n; ++i) a[i] = t[i], fail |= (a[i] != s[i]);
    if (!fail) return x;
  }
  return k + 1;
}
long long check(long long* s) {
  for (long long i = 1; i <= n; ++i) a[i] = i;
  for (long long x = 1; x <= k; ++x) {
    for (long long i = 1; i <= n; ++i) t[i] = a[q[i]];
    bool fail = 0;
    for (long long i = 1; i <= n; ++i) a[i] = t[i], fail |= (a[i] != s[i]);
    if (!fail) return x;
  }
  return k + 1;
}
void yes() {
  puts("YES");
  exit(0);
}
int main() {
  n = read(), k = read();
  bool fail = 0;
  for (long long i = 1; i <= n; ++i) q[i] = read();
  for (long long i = 1; i <= n; ++i)
    end[i] = read(), begin[i] = i, fail |= (end[i] != i);
  if (!fail) return puts("NO"), 0;
  long long x = check(end), y = check_rev(end);
  long long rx = check(begin), ry = check_rev(begin);
  if (k == 1 && (x == 1 || y == 1))
    yes();
  else if (x == 1 && y == 1)
    return puts("NO"), 0;
  else if (x <= k && (k - x) % 2 == 0)
    yes();
  else if (y <= k && (y - k) % 2 == 0)
    yes();
  puts("NO");
  return 0;
}
