#include <bits/stdc++.h>
using namespace std;
long n, k, m[1000 + 1], g[1000 + 1], p[1000 + 1], tmp[1000 + 1], t[1000 + 1];
long long kq;
void doc() {
  cin >> n >> k;
  for (int i = 1; i <= n; i++) cin >> m[i];
  for (int i = 1; i <= n; i++) cin >> g[i];
}
void ktao() {
  for (int i = 1; i <= n; i++) t[i] = i;
}
bool kt() {
  for (int i = 1; i <= n; i++)
    if (g[i] != t[i]) return false;
  return true;
}
void gan() {
  for (int i = 1; i <= n; i++) t[i] = tmp[i];
}
void dich1() {
  for (int i = 1; i <= n; i++) {
    tmp[i] = t[m[i]];
  }
  gan();
}
void dich2() {
  for (int i = 1; i <= n; i++) {
    tmp[m[i]] = t[i];
  }
  gan();
}
bool thu1() {
  long dem = 0;
  ktao();
  dich1();
  if (kt() == true) dem++;
  ktao();
  dich2();
  if (kt() == true) dem++;
  if (dem == 2 and k > 1) {
    cout << "NO";
    return true;
  } else
    return false;
}
void xl() {
  ktao();
  if (kt() == true) {
    if (k > 0) {
      cout << "NO";
      return;
    }
  }
  if (thu1() == true) return;
  ktao();
  for (int i = 1; i <= k; i++) {
    dich1();
    if (kt() == true)
      if ((k - i) % 2 == 0) {
        cout << "YES";
        return;
      } else
        break;
  }
  ktao();
  for (int i = 1; i <= k; i++) {
    dich2();
    if (kt() == true)
      if ((k - i) % 2 == 0) {
        cout << "YES";
        return;
      } else
        break;
  }
  cout << "NO";
}
int main() {
  cin.tie(NULL);
  ios_base::sync_with_stdio(false);
  doc();
  xl();
}
