#include <bits/stdc++.h>
using namespace std;
struct Counter {
  static int k;
  Counter() { k++; }
  ~Counter() { k--; }
};
int Counter::k = 0;
template <typename T>
void pr(const string& name, T t) {
  cout << name << " = " << t << endl;
}
template <typename T, typename... Types>
void pr(const string& names, T t, Types... rest) {
  auto comma_pos = names.find(',');
  cout << names.substr(0, comma_pos) << " = " << t << ", ";
  auto next_name_pos = names.find_first_not_of(" \t\n", comma_pos + 1);
  pr(string(names, next_name_pos), rest...);
}
void mod(long long& a, long long b) {
  a %= b;
  if (a < 0) a += b;
}
const long long MOD = 1000000007;
int A[105], NX[105], Inv[105], Q[105], S[105], N, K;
bool same() {
  for (int i = (1); i <= (N); i++)
    if (A[i] != S[i]) return false;
  return true;
}
void perform(int t) {
  if (t == 0) {
    for (int i = (1); i <= (N); i++) NX[i] = A[Inv[i]];
    for (int i = (1); i <= (N); i++) A[i] = NX[i];
  } else {
    for (int i = (1); i <= (N); i++) NX[i] = A[Q[i]];
    for (int i = (1); i <= (N); i++) A[i] = NX[i];
  }
}
bool ok(int f, int b) {
  for (int i = (1); i <= (N); i++) A[i] = i;
  while (b + f) {
    int prev = b + f;
    if (b) {
      perform(0);
      if (same() && b + f > 1)
        perform(1);
      else {
        b--;
        continue;
      }
    }
    if (f) {
      perform(1);
      if (same() && b + f > 1)
        perform(0);
      else {
        f--;
        continue;
      }
    }
    if (b + f == prev || same()) return false;
  }
  return same();
}
int main() {
  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++) A[i] = i;
  for (int i = (1); i <= (N); i++) Inv[Q[i]] = i;
  bool equal = true;
  for (int i = (1); i <= (N); i++)
    if (A[i] != S[i]) equal = false;
  if (equal) {
    cout << "NO";
    return 0;
  }
  for (int b = (0); b <= (K); b++)
    if (ok(K - b, b)) {
      cout << "YES";
      return 0;
    }
  cout << "NO";
}
