#include <bits/stdc++.h>
using namespace std;
bool equal(int* a, int* b, int length) {
  for (int i = 1; i <= length; i++) {
    if (a[i] != b[i]) {
      return false;
    }
  }
  return true;
}
int main() {
  int n, k;
  cin >> n >> k;
  int change[102], invchange[102];
  int end[102];
  for (int i = 1; i <= n; i++) {
    cin >> change[i];
  }
  for (int i = 1; i <= n; i++) {
    cin >> end[i];
  }
  for (int i = 1; i <= n; i++) {
    invchange[change[i]] = i;
  }
  int tmp[2][102];
  for (int i = 1; i <= n; i++) {
    tmp[0][i] = i;
  }
  if (equal(tmp[0], end, n)) {
    cout << "NO" << endl;
    return 0;
  }
  if (equal(change, invchange, n)) {
    if (equal(change, end, n) && k == 1) {
      cout << "YES" << endl;
      return 0;
    } else {
      cout << "NO" << endl;
      return 0;
    }
  }
  for (int i = 1; i <= k; i++) {
    for (int j = 1; j <= n; j++) {
      tmp[i % 2][change[j]] = tmp[(i + 1) % 2][j];
    }
    if (equal(tmp[i % 2], end, n)) {
      if ((k - i) % 2 == 0) {
        cout << "YES" << endl;
        return 0;
      }
      break;
    }
  }
  for (int i = 1; i <= n; i++) {
    tmp[0][i] = i;
  }
  for (int i = 1; i <= k; i++) {
    for (int j = 1; j <= n; j++) {
      tmp[i % 2][invchange[j]] = tmp[(i + 1) % 2][j];
    }
    if (equal(tmp[i % 2], end, n)) {
      if ((k - i) % 2 == 0) {
        cout << "YES" << endl;
        return 0;
      }
      break;
    }
  }
  cout << "NO" << endl;
  return 0;
}
