#include <bits/stdc++.h>
using namespace std;
const long long LINF = ~(((long long)0x1) << 63) / 2;
const int INF = 0X3F3F3F3F;
const double eps = 1e-7;
int q[110];
int s[110];
int now[110];
int t[110];
int main() {
  int n, k;
  cin >> n >> k;
  for (int i = 1; i <= n; i++) cin >> q[i];
  for (int i = 1; i <= n; i++) cin >> s[i];
  for (int i = 1; i <= n; i++) now[i] = i;
  int a = INF, b = INF;
  for (int i = 0; i <= k; i++) {
    bool flag = true;
    for (int j = 1; j <= n; j++)
      if (now[j] != s[j]) flag = false;
    if (flag) {
      if (((k - i) % 2 == 0 && i > 1) || i == k) {
        cout << "YES" << endl;
        return 0;
      }
      a = i;
      break;
    }
    for (int j = 1; j <= n; j++) t[j] = now[q[j]];
    for (int j = 1; j <= n; j++) now[j] = t[j];
  }
  for (int i = 1; i <= n; i++) now[i] = i;
  for (int i = 0; i <= k; i++) {
    bool flag = true;
    for (int j = 1; j <= n; j++)
      if (now[j] != s[j]) flag = false;
    if (flag) {
      if (((k - i) % 2 == 0 && i > 1) || i == k) {
        cout << "YES" << endl;
        return 0;
      }
      b = i;
      break;
    }
    for (int j = 1; j <= n; j++) t[q[j]] = now[j];
    for (int j = 1; j <= n; j++) now[j] = t[j];
  }
  if (a != INF) {
    if (((k - a) % 2 == 0 && b > 1)) {
      cout << "YES" << endl;
      return 0;
    }
  }
  if (b != INF) {
    if ((k - b) % 2 == 0 && a > 1) {
      cout << "YES" << endl;
      return 0;
    }
  }
  cout << "NO" << endl;
  return 0;
}
