#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:268435456")
using namespace std;
int check(vector<int> q, vector<int> s, int z, int k) {
  int n = q.size();
  vector<int> d(n);
  vector<int> a(n);
  for (int i = 0; i < n; i++) a[i] = i;
  if (a == s) return 0;
  for (int i = 1; i <= k; i++) {
    for (int j = 0; j < n; j++) d[j] = a[q[j]];
    a = d;
    if (a == s) return z ? i % 2 == k % 2 : i == k;
  }
  return 0;
}
int main() {
  int n, k;
  cin >> n >> k;
  vector<int> q(n), s(n), r(n);
  ;
  for (int i = 0; i < n; i++) {
    cin >> q[i];
    q[i]--;
    r[q[i]] = i;
  }
  for (int i = 0; i < n; i++) {
    cin >> s[i];
    s[i]--;
  }
  int z = q != s || r != s;
  cout << (check(q, s, z, k) || check(r, s, z, k) ? "YES" : "NO");
  return 0;
}
