#include <bits/stdc++.h>
using namespace std;
const double EPS = 0.0000001;
const double PI = acos(-1);
const long long INFLL = 0x7FFFFFFFFFFFFFFF;
const int INF = 0x7FFFFFFF;
template <typename T>
inline void next(T &num) {
  char c;
  num = 0;
  do {
    c = getchar_unlocked();
  } while (c != EOF && c == ' ' && c == '\n' && c == '\t');
  int sign = (c == '-' ? -1 : 1);
  if (c != '-') num += (c - '0');
  while ((c = getchar_unlocked()) != EOF && c != '\n' && c != '\t' &&
         c != ' ') {
    num *= 10;
    num += (c - '0');
  }
  num *= sign;
}
inline string getstr() {
  string str;
  char k;
  while ((k = getchar_unlocked()) == ' ' || k == '\n') {
    k = getchar_unlocked();
    if (k == ' ' || k == '\n')
      continue;
    else
      break;
  }
  str.push_back(k);
  while ((k = getchar_unlocked()) != EOF && k != '\n' && k != '\t' &&
         k != '\v' && k != '\0' && k != ' ')
    str.push_back(k);
  return str;
}
int n, k, cur[102], pr[102], ne[102], tmp[102], s[102];
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cin >> n >> k;
  for (int i = int(1), _b = int(n); i <= _b; i++) cin >> ne[i];
  for (int i = int(1), _b = int(n); i <= _b; i++) pr[ne[i]] = i;
  for (int i = int(1), _b = int(n); i <= _b; i++) cin >> s[i];
  int l = -k - 1, r = k + 1;
  for (int i = int(1), _b = int(n); i <= _b; i++) cur[i] = i;
  for (int step = int(0), _b = int(k); step <= _b; step++) {
    bool valid = 1;
    for (int i = int(1), _b = int(n); i <= _b; i++) valid &= (cur[i] == s[i]);
    if (valid) {
      r = step;
      break;
    }
    for (int i = int(1), _b = int(n); i <= _b; i++) tmp[i] = cur[ne[i]];
    for (int i = int(1), _b = int(n); i <= _b; i++) cur[i] = tmp[i];
  }
  for (int i = int(1), _b = int(n); i <= _b; i++) cur[i] = i;
  for (int step = int(0), _b = int(k); step <= _b; step++) {
    bool valid = 1;
    for (int i = int(1), _b = int(n); i <= _b; i++) valid &= (cur[i] == s[i]);
    if (valid) {
      l = -step;
      break;
    }
    for (int i = int(1), _b = int(n); i <= _b; i++) tmp[i] = cur[pr[i]];
    for (int i = int(1), _b = int(n); i <= _b; i++) cur[i] = tmp[i];
  }
  if (l == 0 && r == 0)
    cout << "NO";
  else if (l == -1 && r == 1)
    cout << (k == 1 ? "YES" : "NO");
  else if ((k + l) % 2 == 0 || (k - r) % 2 == 0)
    cout << "YES";
  else
    cout << "NO";
  return 0;
}
