#include <bits/stdc++.h>
using namespace std;
const int mod = 1000000007;
const int inf = 50000000;
const int maxn = 100010;
int p[111], q[111], second[111], temp[111];
int main() {
  int n, k, i, j, eq = 1;
  scanf("%d%d", &n, &k);
  for (i = 1; i <= n; i++) scanf("%d", &q[i]);
  for (i = 1; i <= n; i++) {
    scanf("%d", &second[i]);
    p[i] = i;
    if (p[i] != second[i]) eq = 0;
  }
  if (eq) {
    cout << "NO\n";
    return 0;
  }
  eq = 1;
  for (j = 1; j <= n; j++) {
    temp[j] = p[q[j]];
    if (temp[j] != second[j]) eq = 0;
  }
  for (j = 1; j <= n; j++) {
    temp[q[j]] = p[j];
    if (temp[q[j]] != second[q[j]]) eq = 0;
  }
  if (eq) {
    if (k == 1)
      cout << "YES\n";
    else
      cout << "NO\n";
    return 0;
  }
  for (i = 1; i <= k; i++) {
    eq = 1;
    for (j = 1; j <= n; j++) {
      temp[j] = p[q[j]];
      if (temp[j] != second[j]) eq = 0;
    }
    for (j = 1; j <= n; j++) p[j] = temp[j];
    if (eq && !((k - i) & 1)) {
      cout << "YES\n";
      return 0;
    }
  }
  for (i = 1; i <= n; i++) p[i] = i;
  for (i = 1; i <= k; i++) {
    eq = 1;
    for (j = 1; j <= n; j++) {
      temp[q[j]] = p[j];
      if (temp[q[j]] != second[q[j]]) eq = 0;
    }
    for (j = 1; j <= n; j++) p[j] = temp[j];
    if (eq && !((k - i) & 1)) {
      cout << "YES\n";
      return 0;
    }
  }
  cout << "NO\n";
  return 0;
}
