#include <bits/stdc++.h>
using namespace std;
const int MAX = int(1e2) + 10;
int N, K;
void read(vector<int> &p) {
  p.resize(N + 1);
  for (int i = 1; i <= N; i++) cin >> p[i];
}
vector<int> inv(vector<int> &p) {
  vector<int> ret = vector<int>(N + 1);
  for (int i = 1; i <= N; i++) ret[p[i]] = i;
  return ret;
}
vector<int> apply(vector<int> &p, vector<int> &q) {
  vector<int> ret(N + 1);
  for (int i = 1; i <= N; i++) ret[i] = p[q[i]];
  return ret;
}
bool eq(vector<int> &a, vector<int> &b) {
  int i = 1;
  for (; i <= N && a[i] == b[i]; i++)
    ;
  return i > N;
}
int _times(vector<int> p, vector<int> &q, vector<int> &s) {
  int t = 0;
  for (; t <= K && !eq(p, s); t++) p = apply(p, q);
  return (t <= K) ? t : -1;
}
int main() {
  ios::sync_with_stdio(false);
  cin >> N >> K;
  vector<int> p, q, s, inv_q;
  read(q);
  read(s);
  inv_q = inv(q);
  p.resize(N + 1);
  for (int i = 1; i <= N; i++) p[i] = i;
  if (eq(p, s)) {
    cout << "NO\n";
    return 0;
  }
  int t_q = _times(p, q, s);
  int t_inv_q = _times(p, inv_q, s);
  if (eq(q, inv_q)) {
    if (t_q != -1 && K == 1)
      cout << "YES\n";
    else
      cout << "NO\n";
    return 0;
  }
  if ((t_q != -1 && (K - t_q) % 2 == 0) ||
      (t_inv_q != -1 && (K - t_inv_q) % 2 == 0))
    cout << "YES\n";
  else
    cout << "NO\n";
  return 0;
}
