#include <bits/stdc++.h>
using namespace std;
long long n, k, a, b, p[105] = {0}, q[105] = {0}, s[105] = {0}, t[105] = {0};
template <typename T>
inline void read(T &x) {
  T c = getchar(), f = 0;
  for (; c < 48 || 57 < c; c = getchar())
    if (c == '-') f = 1;
  for (x = 0; 48 <= c && c <= 57; c = getchar())
    x = (x << 3) + (x << 1) + (c ^ 48);
  if (f) x = -x;
}
template <typename T>
inline void print(T x) {
  if (x < 0) x = -x, putchar('-');
  if (x > 9) print(x / 10);
  putchar(x % 10 + 48);
}
signed main() {
  read(n), read(k);
  for (register long long i = 1; i <= n; i++) read(q[i]);
  for (register long long i = 1; i <= n; i++) read(s[i]);
  for (register long long i = 1; i <= n; i++) t[i] = p[i] = i;
  for (register long long i; a <= k; a++) {
    for (i = 1; p[i] == s[i] && i <= n;) i++;
    if (i > n) break;
    for (i = 1; i <= n; i++) t[i] = p[q[i]];
    for (i = 1; i <= n; i++) p[i] = t[i];
  }
  for (register long long i = 1; i <= n; i++) t[i] = p[i] = i;
  for (register long long i; b <= k; b++) {
    for (i = 1; p[i] == s[i] && i <= n;) i++;
    if (i > n) break;
    for (i = 1; i <= n; i++) t[q[i]] = p[i];
    for (i = 1; i <= n; i++) p[i] = t[i];
  }
  if (a == 1 && b == 1 && k == 1)
    puts("YES");
  else if ((a == 1 && b == 1) || (!a && !b) || (a == k + 1 && b == k + 1))
    puts("NO");
  else if ((a + k + 1) % 2 || (b + k + 1) % 2)
    puts("YES");
  else
    puts("NO");
  return 0;
}
