#include <bits/stdc++.h>
template <typename T>
T inline SQR(const T &a) {
  return a * a;
}
template <typename T>
T inline ABS(const T &a) {
  return a < 0 ? -a : a;
}
const double EPS = 1e-9;
inline int SGN(double a) {
  return ((a > EPS) ? (1) : ((a < -EPS) ? (-1) : (0)));
}
inline int CMP(double a, double b) { return SGN(a - b); }
using namespace std;
int q[128], s[128], p[128], aux[128];
int main(int argc, char *argv[]) {
  ios::sync_with_stdio(false);
  int N, k;
  cin >> N >> k;
  for (int i = 1; i <= N; ++i) cin >> q[i];
  for (int i = 1; i <= N; ++i) cin >> s[i];
  for (int i = 1; i <= N; ++i) p[i] = i;
  bool eq = true;
  for (int i = 1; i <= N; ++i)
    if (s[i] != p[i]) eq = false;
  if (eq) {
    cout << "NO\n";
    return 0;
  }
  int norm = 0, inv = 0;
  for (int step = 0; step < k + 1; ++step) {
    eq = true;
    for (int i = 1; i <= N; ++i)
      if (p[i] != s[i]) eq = false;
    if (eq) {
      norm = step;
      break;
    }
    if (step == k) break;
    for (int i = 1; i <= N; ++i) aux[i] = p[q[i]];
    for (int i = 1; i <= N; ++i) p[i] = aux[i];
  }
  for (int i = 1; i <= N; ++i) p[i] = i;
  for (int step = 0; step < k + 1; ++step) {
    eq = true;
    for (int i = 1; i <= N; ++i)
      if (p[i] != s[i]) eq = false;
    if (eq) {
      inv = step;
      break;
    }
    if (step == k) break;
    for (int i = 1; i <= N; ++i) aux[q[i]] = p[i];
    for (int i = 1; i <= N; ++i) p[i] = aux[i];
  }
  bool ok = false;
  if (norm || inv) {
    if (norm == k || inv == k) ok = true;
    if (norm) {
      if (((k - norm) % 2) == 0) {
        int gg = (norm - 1);
        if (inv)
          gg += inv - 1;
        else
          gg++;
        if (gg) ok = true;
      }
    }
    if (inv) {
      if (((k - inv) % 2) == 0) {
        int gg = (inv - 1);
        if (norm)
          gg += norm - 1;
        else
          gg++;
        if (gg) ok = true;
      }
    }
  }
  if (ok)
    cout << "YES\n";
  else
    cout << "NO\n";
  return 0;
}
