#include <bits/stdc++.h>
using namespace std;
int n;
vector<int> p;
void permutate(vector<int> &v) {
  vector<int> aux(n);
  for (int i = 0; i < n; i++) {
    aux[p[i]] = v[i];
  }
  v = aux;
}
void invPermutate(vector<int> &v) {
  vector<int> aux(n);
  for (int i = 0; i < n; i++) {
    aux[i] = v[p[i]];
  }
  v = aux;
}
int main() {
  vector<int> v, aux, ini;
  int k;
  scanf("%d%d", &n, &k);
  v.resize(n);
  p.resize(n);
  aux.resize(n);
  for (int i = 0; i < n; i++) scanf("%d", &p[i]), p[i]--;
  for (int i = 0; i < n; i++) scanf("%d", &v[i]), v[i]--;
  for (int i = 0; i < n; i++) aux[i] = i;
  ini = aux;
  bool aa = 0, bb = 0;
  if (v == aux) {
    puts("NO");
    return 0;
  }
  int a = 0, b = 0;
  for (int i = 0; i < k; i++) {
    a++;
    permutate(aux);
    if (v == aux) {
      aa = 1;
      break;
    }
  }
  aux = ini;
  for (int i = 0; i < k; i++) {
    b++;
    invPermutate(aux);
    if (v == aux) {
      bb = 1;
      break;
    }
  }
  if (a == 1 && b == 1)
    puts(k == 1 && (aa || bb) ? "YES" : "NO");
  else if (aa && (k == a || ((k - a) % 2 == 0)))
    puts("YES");
  else if (bb && (k == b || ((k - b) % 2 == 0)))
    puts("YES");
  else
    puts("NO");
}
