#include <bits/stdc++.h>
using namespace std;
using namespace std;
const int N = 10005;
int n, k, z;
int a[N], q[N], v[N], b[N], s[N];
int main() {
  cin >> n >> k;
  for (int i = 1; i <= n; ++i) scanf("%d", &q[i]);
  for (int i = 1; i <= n; ++i) v[q[i]] = i;
  for (int i = 1; i <= n; ++i) scanf("%d", &s[i]);
  int left = -k - 1;
  int right = k + 1;
  for (int i = 1; i <= n; ++i) a[i] = i;
  for (z = 0; z <= k; ++z) {
    int ok = 1;
    for (int i = 1; i <= n; ++i)
      if (a[i] != s[i]) ok = 0;
    if (ok) {
      right = z;
      break;
    }
    for (int i = 1; i <= n; ++i) b[i] = a[q[i]];
    for (int i = 1; i <= n; ++i) a[i] = b[i];
  }
  for (int i = 1; i <= n; ++i) a[i] = i;
  for (z = 0; z >= -k; --z) {
    int ok = 1;
    for (int i = 1; i <= n; ++i)
      if (a[i] != s[i]) ok = 0;
    if (ok) {
      left = z;
      break;
    }
    for (int i = 1; i <= n; ++i) b[i] = a[v[i]];
    for (int i = 1; i <= n; ++i) a[i] = b[i];
  }
  if (left == 0 && right == 0)
    puts("NO");
  else if (k == 1 && (left == -1 || right == 1))
    puts("YES");
  else if (left == -1 && right == 1)
    puts("NO");
  else if ((k + left) % 2 == 0 || (k - right) % 2 == 0)
    puts("YES");
  else
    puts("NO");
  return 0;
}
