#include <bits/stdc++.h>
using namespace std;
const int MAX_N = 111;
int p[MAX_N], s[MAX_N], tmp[MAX_N], now[MAX_N];
int main() {
  int n, turns;
  cin >> n >> turns;
  for (int i = 1; i <= n; i++) cin >> p[i];
  for (int i = 1; i <= n; i++) cin >> s[i];
  bool ok = false;
  for (int i = 1; i <= n; i++) ok |= (s[i] != i);
  if (!ok) {
    cout << "NO" << endl;
    return 0;
  }
  ok = false;
  int k1 = 0, k2 = 0;
  for (int i = 1; i <= n; i++) now[i] = i;
  for (int k = 1; k <= turns; k++) {
    for (int i = 1; i <= n; i++) tmp[i] = now[p[i]];
    for (int i = 1; i <= n; i++) now[i] = tmp[i];
    bool match = true;
    for (int i = 1; i <= n; i++) match &= (now[i] == s[i]);
    if (match) {
      if ((k & 1) == (turns & 1)) ok = true, k1 = k;
      break;
    }
  }
  for (int i = 1; i <= n; i++) now[i] = i;
  for (int k = 1; k <= turns; k++) {
    for (int i = 1; i <= n; i++) tmp[p[i]] = now[i];
    for (int i = 1; i <= n; i++) now[i] = tmp[i];
    bool match = true;
    for (int i = 1; i <= n; i++) match &= (now[i] == s[i]);
    if (match) {
      if ((k & 1) == (turns & 1)) ok = true, k2 = k;
      break;
    }
  }
  if (k1 == 1 && k2 == 1 && turns != 1) ok = false;
  if (ok)
    cout << "YES" << endl;
  else
    cout << "NO" << endl;
  return 0;
}
