#include <bits/stdc++.h>
using namespace std;
int n, k;
vector<int> odw(vector<int> p) {
  vector<int> res(n, 0);
  for (int i = 0; i < (n); i++) res[p[i]] = i;
  return res;
}
vector<int> mnoz(vector<int> a, vector<int> b) {
  vector<int> res(n, 0);
  for (int i = 0; i < (n); i++) res[i] = a[b[i]];
  return res;
}
vector<int> in() {
  vector<int> res(n, 0);
  for (int i = 0; i < (n); i++) cin >> res[i];
  for (int i = 0; i < (n); i++) res[i]--;
  return res;
}
vector<int> id() {
  vector<int> res(n, 0);
  for (int i = 0; i < (n); i++) res[i] = i;
  return res;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin >> n >> k;
  vector<int> a = in();
  vector<int> b = in();
  bool res = false;
  if (b == id())
    res = false;
  else if (odw(a) == a)
    res = (a == b && k == 1);
  else {
    for (int ewqewq = 0; ewqewq < (2); ewqewq++) {
      vector<int> x = a;
      for (int q = (1); q <= (k); q++) {
        if (x == b && q % 2 == k % 2) res = true;
        x = mnoz(x, a);
      }
      a = odw(a);
    }
  }
  cout << (res ? "YES" : "NO") << endl;
  return 0;
}
