#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, k;
  cin >> n >> k;
  vector<int> q(n + 1, 0), e(n + 1, 0), s(n + 1, 0), cur(n + 1, 0),
      temp(n + 1, 0);
  for (int i = 0; i < n; i++) {
    cin >> q[i + 1];
    e[q[i + 1]] = i + 1;
  }
  for (int i = 0; i < n; i++) {
    cin >> s[i + 1];
    cur[i + 1] = i + 1;
  }
  if (cur == s) {
    cout << "NO";
    return 0;
  }
  for (int i = 0; i < k; i++) {
    for (int j = 1; j <= n; j++) temp[j] = cur[q[j]];
    cur = temp;
    if (cur == s) {
      if (e == q) {
        if (i == 0) {
          if (k == 1)
            cout << "YES";
          else
            cout << "NO";
          return 0;
        } else {
          cout << "NO";
          return 0;
        }
      }
      if ((k - i - 1) % 2 == 0) {
        cout << "YES";
        return 0;
      }
      break;
    }
  }
  for (int i = 0; i < n; i++) cur[i + 1] = i + 1;
  for (int i = 0; i < k; i++) {
    for (int j = 1; j <= n; j++) temp[j] = cur[e[j]];
    cur = temp;
    if (cur == s) {
      if ((k - i - 1) % 2 == 0) {
        cout << "YES";
        return 0;
      }
      break;
    }
  }
  cout << "NO";
  return 0;
}
