#include <bits/stdc++.h>
using namespace std;
const int maxn = 100005;
int main() {
  int n, k, tmp;
  set<vector<int> > p;
  cin >> n >> k;
  vector<int> tar(n + 1), per(n + 1), rev(n + 1), del(n + 1);
  for (int i = 1; i <= n; i++) {
    cin >> tmp;
    per[i] = tmp;
    rev[tmp] = i;
  }
  for (int i = 1; i <= n; i++) cin >> tar[i];
  tmp = k - 1;
  vector<int> init(n + 1);
  init = per;
  if (k % 2) p.insert(init);
  while (tmp) {
    for (int i = 0; i < init.size(); i++) init[i] = per[init[i]];
    if (tmp % 2) p.insert(init);
    tmp--;
  }
  tmp = k - 1;
  init = rev;
  if (k % 2) p.insert(init);
  while (tmp) {
    for (int i = 0; i < init.size(); i++) init[i] = rev[init[i]];
    if (tmp % 2) p.insert(init);
    tmp--;
  }
  if ((per == rev) && k % 2 && k > 1) {
    p.erase(per);
  }
  for (int i = 0; i <= n; i++) del[i] = i;
  if (p.find(del) != p.end()) p.erase(del);
  if (p.find(tar) != p.end())
    cout << "YES" << endl;
  else
    cout << "NO" << endl;
  return 0;
}
