#include <bits/stdc++.h>
using namespace std;
int n;
vector<int> A;
vector<int> B;
vector<int> forward(vector<int> v) {
  vector<int> nex(n + 1);
  for (int i = 1; i <= n; ++i) nex[i] = v[B[i]];
  return nex;
}
vector<int> backward(vector<int> v) {
  vector<int> nex(n + 1);
  for (int i = 1; i <= n; ++i) nex[B[i]] = v[i];
  return nex;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  int k;
  cin >> n >> k;
  A.resize(n + 1);
  B.resize(n + 1);
  for (int i = 1; i <= n; ++i) cin >> B[i];
  for (int i = 1; i <= n; ++i) cin >> A[i];
  vector<int> goal(n + 1);
  for (int i = 1; i <= n; ++i) goal[i] = i;
  if (goal == A ||
      (k > 2 && k % 2 && forward(goal) == A && backward(goal) == A))
    return cout << "NO" << endl, 0;
  int a = 0;
  auto cur = goal;
  while (a <= k && cur != A) {
    cur = forward(cur);
    ++a;
  }
  if (a <= k && (k - a) % 2 == 0) return cout << "YES" << endl, 0;
  cur = goal;
  a = 0;
  while (a <= k && cur != A) {
    cur = backward(cur);
    ++a;
  }
  if (a <= k && (k - a) % 2 == 0) return cout << "YES" << endl, 0;
  cout << "NO" << endl;
  return 0;
}
