#include <bits/stdc++.h>
using namespace std;
const int N = 105;
int n, k, q[N], s[N], a[N], b[N];
bool same() {
  for (int i = 1; i <= n; i++)
    if (a[i] != s[i]) return 0;
  return 1;
}
void do1() {
  for (int i = 1; i <= n; i++) b[i] = a[i];
  for (int i = 1; i <= n; i++) a[q[i]] = b[i];
}
void do2() {
  for (int i = 1; i <= n; i++) b[i] = a[i];
  for (int i = 1; i <= n; i++) a[i] = b[q[i]];
}
int get(bool o) {
  for (int i = 0; i <= k; i++) {
    if (same()) return i;
    if (o)
      do1();
    else
      do2();
  }
  return -1;
}
void rst() {
  for (int i = 1; i <= n; i++) a[i] = i;
}
bool check(int x, int y) {
  bool z = (k - x) % 2 == 0 && k != x && (max(x, y) <= 1 && min(x, y) != -1);
  return (z || x == -1 || (k - x) % 2 != 0);
}
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];
  rst();
  int x = get(1);
  rst();
  int y = get(0);
  if (check(x, y) && check(y, x))
    cout << "NO";
  else
    cout << "YES";
}
