#include <bits/stdc++.h>
using namespace std;
int n;
vector<int> perm(const vector<int>& w, const vector<int>& t) {
  vector<int> res(n);
  for (int i = 0; i < n; ++i) res[w[i]] = t[i];
  return res;
}
int main() {
  int k;
  cin >> n >> k;
  vector<int> q(n), s(n);
  for (int i = 0; i < n; ++i) {
    cin >> q[i];
    --q[i];
  }
  for (int i = 0; i < n; ++i) {
    cin >> s[i];
    --s[i];
  }
  vector<int> first(n);
  for (int i = 0; i < n; ++i) first[i] = i;
  vector<int> inv = perm(q, first);
  vector<int> next = first;
  int a = -1, b = -1;
  for (int i = 0; i <= k; ++i) {
    if (next == s) {
      a = i;
      break;
    }
    next = perm(q, next);
  }
  next = first;
  for (int i = 0; i <= k; ++i) {
    if (next == s) {
      b = i;
      break;
    }
    next = perm(inv, next);
  }
  bool yes = k == a || k == b;
  yes |= (a != -1 && ((k - a) % 2 == 0 && (a > 1 || (a == 1 && b != 1))));
  yes |= (b != -1 && ((k - b) % 2 == 0 && (b > 1 || (b == 1 && a != 1))));
  cout << (yes ? "YES" : "NO");
  return 0;
}
