#include <bits/stdc++.h>
using namespace std;
const long long N = 510;
inline long long read() {
  long long s = 0, w = 1;
  register char ch = getchar();
  while (ch < '0' || ch > '9') {
    if (ch == '-') w = -1;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9')
    s = (s << 3) + (s << 1) + (ch ^ 48), ch = getchar();
  return s * w;
}
void print(long long x) {
  if (x < 0) x = -x, putchar('-');
  if (x > 9) print(x / 10);
  putchar(x % 10 + '0');
}
long long n, k, w1, w2, a[N], b[N], q[N], s[N];
inline bool Check() {
  for (register long long i = 1; i <= n; i++)
    if (b[i] ^ s[i]) return 0;
  return 1;
}
signed main() {
  n = read(), k = read();
  for (register long long i = 1; i <= n; i++) a[i] = b[i] = i, q[i] = read();
  for (register long long i = 1; i <= n; i++) s[i] = read();
  for (; w1 <= k; w1++) {
    if (Check()) break;
    for (register long long i = 1; i <= n; i++) b[i] = a[q[i]];
    for (register long long i = 1; i <= n; i++) a[i] = b[i];
  }
  for (register long long i = 1; i <= n; i++) a[i] = b[i] = i;
  for (; w2 <= k; w2++) {
    if (Check()) break;
    for (register long long i = 1; i <= n; i++) b[q[i]] = a[i];
    for (register long long i = 1; i <= n; i++) a[i] = b[i];
  }
  if (!w1 || !w2)
    puts("NO");
  else if (w1 == 1 && w2 == 1 && k > 1)
    puts("NO");
  else if (w1 == k + 1 && w2 == k + 1)
    puts("NO");
  else if (w1 <= k && (k - w1) % 2 == 0 || w2 <= k && (k - w2) % 2 == 0)
    puts("YES");
  else
    puts("NO");
  return 0;
}
