#include <bits/stdc++.h>
using namespace std;
int n, k;
vector<int> q, s, p, qinv;
int stepsreqd1 = 0, stepsreqd2 = 0, stepsrem = 0;
inline void applyKtimes(vector<int> &a, vector<int> &b, int &stepsreqd) {
  stepsreqd = 0;
  for (int i = 0; i <= k; i++) {
    if (a == s) {
      stepsreqd = i;
      break;
    }
    vector<int> tmp(n);
    for (int i = 0; i < n; i++) tmp[i] = a[b[i]];
    a = tmp;
  }
}
int main() {
  cin >> n >> k;
  q.resize(n), s.resize(n), p.resize(n), qinv.resize(n);
  vector<int> PP(n);
  for (int i = 0; i < n; i++) {
    cin >> q[i];
    q[i]--;
    qinv[q[i]] = i;
    PP[i] = i;
  }
  for (int i = 0; i < n; i++) {
    cin >> s[i];
    s[i]--;
  }
  p = PP;
  stepsreqd1 = 0;
  applyKtimes(p, q, stepsreqd1);
  p = PP;
  stepsreqd2 = 0;
  applyKtimes(p, qinv, stepsreqd2);
  bool flag;
  if (stepsreqd1 == 1 && stepsreqd2 == 1 && k > 1)
    flag = 0;
  else if (((k - stepsreqd1) % 2 == 0 && stepsreqd1 != 0) ||
           ((k - stepsreqd2) % 2 == 0 && stepsreqd2 != 0))
    flag = 1;
  else
    flag = 0;
  if (flag)
    cout << "YES"
         << "\n";
  else
    cout << "NO"
         << "\n";
  return 0;
}
