#include <bits/stdc++.h>
using namespace std;
int q[111], qr[111], s[111];
int d[222][111];
int dp[111][222];
bool ss[222];
int n, k;
bool rec(int kk, int i) {
  if (dp[kk][k + i] != -1) return dp[kk][k + i];
  if (kk == 0) return ss[k + i];
  bool r;
  if (ss[k + i])
    r = false;
  else {
    r = rec(kk - 1, i - 1) || rec(kk - 1, i + 1);
  }
  return dp[kk][k + i] = r;
}
int main() {
  cin >> n >> k;
  for (int(i) = 0; (i) < (int)(n); ++(i)) cin >> q[i], q[i]--;
  for (int(i) = 0; (i) < (int)(n); ++(i)) cin >> s[i], s[i]--;
  for (int(i) = 0; (i) < (int)(n); ++(i)) qr[q[i]] = i;
  for (int(i) = 0; (i) < (int)(n); ++(i)) d[k + 0][i] = i;
  for (int(i) = (int)(1); (i) <= (int)(k); ++(i))
    for (int(j) = 0; (j) < (int)(n); ++(j)) d[k + i][j] = d[k + i - 1][q[j]];
  for (int(i) = (int)(1); (i) <= (int)(k); ++(i))
    for (int(j) = 0; (j) < (int)(n); ++(j)) d[k - i][j] = d[k + -i + 1][qr[j]];
  for (int(i) = (int)(-k); (i) <= (int)(k); ++(i)) {
    ss[k + i] = vector<int>(d[k + i], d[k + i] + n) == vector<int>(s, s + n);
  }
  memset(dp, -1, sizeof(dp));
  bool r = rec(k, 0);
  cout << (r ? "YES" : "NO") << endl;
  return 0;
}
