#include <bits/stdc++.h>
std::vector<int> q, s;
int n, k;
void fwd(std::vector<int> &p) {
  std::vector<int> t(n);
  for (int i = 0; i < n; ++i) t[i] = p[q[i]];
  p = t;
}
void back(std::vector<int> &p) {
  std::vector<int> t(n);
  for (int i = 0; i < n; ++i) t[q[i]] = p[i];
  p = t;
}
void yes() {
  std::cout << "YES\n";
  exit(0);
}
void no() {
  std::cout << "NO\n";
  exit(0);
}
int main() {
  std::cin >> n >> k;
  q.resize(n);
  s.resize(n);
  for (int i = 0; i < n; ++i) {
    std::cin >> q[i];
    --q[i];
  }
  for (int i = 0; i < n; ++i) {
    std::cin >> s[i];
    --s[i];
  }
  std::vector<int> p(n);
  int a = -1, b = -1;
  for (int i = 0; i < n; ++i) p[i] = i;
  for (int i = 0; i <= k; ++i) {
    if (p == s) {
      a = i;
      break;
    }
    fwd(p);
  }
  for (int i = 0; i < n; ++i) p[i] = i;
  for (int i = 0; i <= k; ++i) {
    if (p == s) {
      b = i;
      break;
    }
    back(p);
  }
  if (a < 0 && b < 0) no();
  if (a < 0 || b < 0) {
    int z = a < 0 ? b : a;
    if ((k - z) % 2 == 0)
      yes();
    else
      no();
  }
  if (a == 0 && b == 0) no();
  if (a == 1 && b == 1) {
    if (k == 1)
      yes();
    else
      no();
  }
  if ((k - a) % 2 == 0) yes();
  if ((k - b) % 2 == 0) yes();
  no();
  return 0;
}
