#include <bits/stdc++.h>
using namespace std;
vector<int> Prod(const vector<int> &l, const vector<int> &r) {
  int n = l.size();
  vector<int> res(n);
  for (int i = 0; i < n; ++i) res[i] = l[r[i]];
  return res;
}
vector<int> ProdInv(const vector<int> &l, const vector<int> &r) {
  int n = l.size();
  vector<int> rev(n);
  for (int i = 0; i < n; ++i) rev[r[i]] = i;
  return Prod(l, rev);
}
bool IsEqual(const vector<int> &l, const vector<int> &r) {
  for (int i = 0; i < l.size(); ++i)
    if (l[i] != r[i]) return false;
  return true;
}
bool IsOk(const vector<int> &l, const vector<int> &r, const vector<int> &s) {
  return !IsEqual(l, s) || !IsEqual(r, s);
}
int main() {
  int n, k;
  cin >> n >> k;
  vector<int> inp(n), s(n);
  for (int i = 0; i < n; ++i) {
    cin >> inp[i];
    --inp[i];
  }
  for (int i = 0; i < n; ++i) {
    cin >> s[i];
    --s[i];
  }
  for (int d = 0; 2 * d <= k; ++d) {
    bool isGood = true;
    vector<int> p(n);
    for (int i = 0; i < n; ++i) p[i] = i;
    if (IsEqual(p, s)) {
      break;
    }
    if (!IsOk(Prod(p, inp), ProdInv(p, inp), s) && d > 0) {
      break;
    }
    for (int j = 0; j < k - 2 * d; ++j) {
      if (IsEqual(p, s)) isGood = false;
      p = Prod(p, inp);
    }
    if (IsEqual(p, s) && isGood) {
      cout << "YES";
      return 0;
    }
    isGood = true;
    for (int i = 0; i < n; ++i) p[i] = i;
    for (int j = 0; j < k - 2 * d; ++j) {
      if (IsEqual(p, s)) isGood = false;
      p = ProdInv(p, inp);
    }
    if (IsEqual(p, s) && isGood) {
      cout << "YES";
      return 0;
    }
  }
  cout << "NO";
  return 0;
}
