#include <bits/stdc++.h>
using namespace std;
vector<int> q, s;
vector<int> p;
int n, k;
void nxt() {
  vector<int> ans;
  for (int i = 0; i < n; i++) {
    ans.push_back(p[q[i] - 1]);
  }
  p = ans;
}
void prev() {
  vector<int> ans;
  ans.resize(n);
  for (int i = 0; i < n; i++) {
    ans[q[i] - 1] = p[i];
  }
  p = ans;
}
void init() {
  for (int i = 0; i < n; i++) p[i] = i + 1;
}
int solve1() {
  init();
  int r = 0;
  for (int it = 0; it <= k; it++) {
    if (p == s) break;
    r++;
    nxt();
  }
  return r;
}
int solve2() {
  init();
  int r = 0;
  for (int it = 0; it <= k; it++) {
    if (p == s) break;
    r++;
    prev();
  }
  return r;
}
int main() {
  cin >> n >> k;
  q.resize(n);
  s.resize(n);
  p.resize(n);
  for (int i = 0; i < n; i++) cin >> q[i];
  for (int i = 0; i < n; i++) cin >> s[i];
  init();
  int r1 = solve1();
  int r2 = solve2();
  if (r1 == k || r2 == k) {
    puts("YES");
    return 0;
  }
  if (r1 < 2 && r2 < 2) {
    puts("NO");
    return 0;
  }
  if (r1 == 0 || r2 == 0) {
    puts("NO");
    return 0;
  }
  if (r1 <= k) {
    if (!((k - r1) & 1)) {
      puts("YES");
      return 0;
    }
  }
  if (r2 <= k) {
    if (!((k - r2) & 1)) {
      puts("YES");
      return 0;
    }
  }
  puts("NO");
}
