#include <bits/stdc++.h>
using namespace std;
const int INF = 2147483647;
const long long LLINF = 9223372036854775807LL;
int n, k;
int p[200], q[200], s[200], t[200], p1[200], p2[200];
int co1 = 0, co2 = 0;
bool check1() {
  for (int i = 1; i <= n; i++)
    if (p1[i] != s[i]) return false;
  return true;
}
bool check2() {
  for (int i = 1; i <= n; i++)
    if (p2[i] != s[i]) return false;
  return true;
}
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++) {
    p[i] = i;
    p1[i] = i;
    p2[i] = i;
  }
  while (!check1()) {
    for (int i = 1; i <= n; i++) t[i] = p1[q[i]];
    for (int i = 1; i <= n; i++) p1[i] = t[i];
    co1++;
    if (co1 > k) break;
  }
  while (!check2()) {
    for (int i = 1; i <= n; i++) t[q[i]] = p2[i];
    for (int i = 1; i <= n; i++) p2[i] = t[i];
    co2++;
    if (co2 > k) break;
  }
  if (co1 == 1 && co2 == 1 && k != 1) {
    bool eq = true;
    for (int i = 1; i <= n; i++)
      if (p1[i] != p2[i]) eq = false;
    if (eq) {
      cout << "NO\n";
      exit(0);
    }
  }
  bool b1 = false, b2 = false;
  if (co1 == 0 || co1 > k || (k - co1) % 2) {
    b1 = true;
  }
  if (co2 == 0 || co2 > k || (k - co2) % 2) {
    b2 = true;
  }
  if (b1 && b2) {
    cout << "NO\n";
  } else {
    cout << "YES\n";
  }
  return 0;
}
