#include <bits/stdc++.h>
using namespace std;
int i, j, n, m, k;
vector<int> p, s;
int main() {
  srand(time(NULL));
  cin >> n >> k;
  vector<int> q(n + 1), rq(n + 1), np(n + 1);
  p.resize(n + 1);
  s.resize(n + 1);
  for (i = 1; i <= n; i++) cin >> q[i];
  for (i = 1; i <= n; i++)
    for (j = 1; j <= n; j++)
      if (q[j] == i) rq[i] = j;
  for (i = 1; i <= n; i++) cin >> s[i];
  for (i = 1; i <= n; i++) p[i] = i;
  if (p == s) {
    cout << "NO";
    return 0;
  }
  for (i = 1; i <= k; i++) {
    for (j = 1; j <= n; j++) np[j] = p[q[j]];
    p = np;
    if (p == s) {
      if (i == k || (rq != q && (k - i) % 2 == 0)) {
        cout << "YES";
        return 0;
      } else
        break;
    }
  }
  for (i = 1; i <= n; i++) p[i] = i;
  for (i = 1; i <= k; i++) {
    for (j = 1; j <= n; j++) np[j] = p[rq[j]];
    p = np;
    if (p == s) {
      if (i == k || (rq != q && (k - i) % 2 == 0)) {
        cout << "YES";
        return 0;
      } else
        break;
    }
  }
  cout << "NO";
  return 0;
}
