#include <bits/stdc++.h>
using namespace std;
int n, k;
vector<int> p, q, g;
map<pair<int, vector<int> >, int> ma;
int rec(int kk, vector<int> &v) {
  if (kk == 0 && v == g) return 1;
  if (kk == 0) return -1;
  if (v == g) return -1;
  vector<int> v1(n), v2(n);
  for (int i = 0; i < n; i++) {
    v1[i] = v[q[i] - 1];
  }
  for (int i = 0; i < n; i++) {
    v2[q[i] - 1] = v[i];
  }
  int &l1 = ma[make_pair(kk - 1, v1)];
  int &l2 = ma[make_pair(kk - 1, v2)];
  if (l1 == 0) l1 = rec(kk - 1, v1);
  if (l2 == 0) l2 = rec(kk - 1, v2);
  return max(l1, l2);
}
int main() {
  cin >> n >> k;
  p.resize(n);
  q.resize(n);
  g.resize(n);
  for (int i = 0; i < n; i++) {
    cin >> q[i];
    p[i] = i + 1;
  }
  for (int i = 0; i < n; i++) cin >> g[i];
  ma.clear();
  int l = rec(k, p);
  if (l == 1)
    cout << "YES" << endl;
  else
    cout << "NO" << endl;
  return 0;
}
