#include <bits/stdc++.h>
using namespace std;
static const double EPS = 1e-5;
int main() {
  int n, k;
  cin >> n >> k;
  vector<int> cur(n);
  vector<int> p(n);
  vector<int> goal(n);
  for (int i = 0; i < n; i++) {
    cin >> p[i];
  }
  for (int i = 0; i < n; i++) cin >> goal[i];
  bool ok = true;
  for (int i = 0; i < n; i++) {
    cur[i] = i + 1;
    if (goal[i] != cur[i]) ok = false;
  }
  if (ok) {
    cout << "NO" << endl;
    return 0;
  }
  int step_forward = 1000;
  int step_backward = 1000;
  for (int i = 0; i < k; i++) {
    bool ok = true;
    vector<int> nxt;
    for (int j = 0; j < n; j++) {
      nxt.push_back(cur[p[j] - 1]);
      if (nxt[j] != goal[j]) ok = false;
    }
    if (ok) {
      step_forward = i + 1;
      break;
    }
    cur = nxt;
  }
  cur = goal;
  for (int i = 0; i < k; i++) {
    bool ok = true;
    vector<int> nxt;
    for (int j = 0; j < n; j++) {
      nxt.push_back(cur[p[j] - 1]);
      if (nxt[j] != j + 1) ok = false;
    }
    if (ok) {
      step_backward = i + 1;
      break;
    }
    cur = nxt;
  }
  if (step_forward == 1 && step_backward == 1 && k > 1) {
    cout << "NO" << endl;
    return 0;
  }
  if (step_forward <= k && step_forward % 2 == k % 2) {
    cout << "YES" << endl;
    return 0;
  }
  if (step_backward <= k && step_backward % 2 == k % 2) {
    cout << "YES" << endl;
    return 0;
  }
  cout << "NO" << endl;
  return 0;
}
