#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:67108864")
using namespace std;
const long double pi = 3.1415926535897932384626433832795;
const long double eps = 0.000000001;
const int INF = 1E9;
const int MAXN = 111;
int n, k, a, aa, b, bb;
vector<int> q, s, p, pp, pn;
int main() {
  scanf("%d%d", &n, &k);
  q.resize(n + 1);
  s.resize(n + 1);
  p.resize(n + 1);
  pn.resize(n + 1);
  for (int i = 0; i < (int)(n); i++) scanf("%d", &q[i + 1]);
  for (int i = 0; i < (int)(n); i++) scanf("%d", &s[i + 1]);
  for (int i = 0; i < (int)(n); i++) p[i + 1] = i + 1;
  if (p == s) {
    cout << "NO";
    return 0;
  }
  a = b = INF;
  pp = p;
  for (int i = 0; i < (int)(k); i++) {
    for (int j = (int)(1); j < (int)(n + 1); j++) pn[j] = p[q[j]];
    p = pn;
    if (p == s && a == INF) a = i + 1;
  }
  p = pp;
  for (int i = 0; i < (int)(k); i++) {
    for (int j = (int)(1); j < (int)(n + 1); j++) pn[q[j]] = p[j];
    p = pn;
    if (p == s && b == INF) b = i + 1;
  }
  if (a == INF && b == INF || a == 1 && b == 1 && k != 1) {
    cout << "NO";
    return 0;
  }
  if ((a != INF && abs(a - k) % 2 == 0) || (b != INF && abs(b - k) % 2 == 0)) {
    cout << "YES";
    return 0;
  } else {
    cout << "NO";
    return 0;
  }
  return 0;
}
