#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, k;
  cin >> n >> k;
  int q[120], s[120], y[120], l[120];
  bool p = true;
  for (int i = 1; i <= n; i++) cin >> q[i];
  for (int i = 1; i <= n; i++) {
    cin >> s[i];
    y[i] = i;
    if (s[i] != i) p = false;
  }
  if (p) {
    cout << "NO" << endl;
    return 0;
  }
  int t1, t2;
  for (t1 = 1; t1 <= k; t1++) {
    for (int i = 1; i <= n; i++) l[i] = y[q[i]];
    bool p = true;
    for (int i = 1; i <= n; i++)
      if (l[i] != s[i]) {
        p = false;
        break;
      }
    if (p)
      break;
    else {
      for (int i = 1; i <= n; i++) y[i] = l[i];
    }
  }
  for (int i = 1; i <= n; i++) y[i] = i;
  for (t2 = 1; t2 <= k; t2++) {
    for (int i = 1; i <= n; i++) l[q[i]] = y[i];
    bool p = true;
    for (int i = 1; i <= n; i++)
      if (l[i] != s[i]) {
        p = false;
        break;
      }
    if (p)
      break;
    else {
      for (int i = 1; i <= n; i++) y[i] = l[i];
    }
  }
  if (t1 == k || t2 == k) {
    cout << "YES";
    return 0;
  }
  if (t1 > k && t2 > k) {
    cout << "NO" << endl;
    return 0;
  }
  if (k > t1 && (k - t1) % 2 == 0 && (t1 > 1 || t2 > 1)) {
    cout << "YES" << endl;
    return 0;
  }
  if (k > t2 && (k - t2) % 2 == 0 && (t1 > 1 || t2 > 1)) {
    cout << "YES" << endl;
    return 0;
  }
  cout << "NO";
  return 0;
}
