#include <bits/stdc++.h>
using namespace std;
vector<int> Perm(vector<int>& p, vector<int>& q) {
  vector<int> res(p.size());
  for (int i = 0; i < p.size(); i++) res[i] = p[q[i] - 1];
  return res;
}
vector<int> InvPerm(vector<int>& p, vector<int>& q) {
  vector<int> res(p.size());
  for (int i = 0; i < p.size(); i++) res[q[i] - 1] = p[i];
  return res;
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int n, k;
  cin >> n >> k;
  vector<int> p1(n), q(n), s(n), p2(n);
  for (auto& x : q) cin >> x;
  for (auto& x : s) cin >> x;
  for (int i = 0; i < n; i++) p1[i] = p2[i] = i + 1;
  if (p1 == s) return cout << "NO", 0;
  if (Perm(p1, q) == InvPerm(p1, q))
    return cout << (Perm(p1, q) == s && k == 1 ? "YES\n" : "NO\n"), 0;
  for (int j = 0; j < k; j++) {
    p1 = Perm(p1, q);
    if (p1 == s) {
      if ((k - j - 1) % 2 == 0) return cout << "YES\n", 0;
      break;
    }
  }
  for (int j = 0; j < k; j++) {
    p2 = InvPerm(p2, q);
    if (p2 == s) {
      if ((k - j - 1) % 2 == 0) return cout << "YES\n", 0;
      break;
    }
  }
  return cout << "NO", 0;
}
