#include <bits/stdc++.h>
using namespace std;
const int N = 102;
bool dp[N][2 * N + 10];
int n, k, q[N], second[N], perm[2 * N + 10][N];
bool isBad[N];
void mul(int x[], int y[], int z[], int sz) {
  for (int i = 1; i <= sz; ++i) z[i] = x[y[i]];
}
int main() {
  cin >> n >> k;
  for (int i = 1; i <= n; ++i) cin >> q[i];
  for (int i = 1; i <= n; ++i) cin >> second[i];
  int revq[N];
  for (int i = 1; i <= n; ++i) perm[N][i] = i;
  for (int i = 1; i <= n; ++i) revq[q[i]] = i;
  for (int i = -1; i >= -k; --i) mul(perm[i + N + 1], revq, perm[i + N], n);
  for (int i = 1; i <= k; ++i) mul(perm[i + N - 1], q, perm[i + N], n);
  for (int i = -k; i <= k; ++i) {
    bool all = true;
    for (int j = 1; j <= n && all; ++j) all &= second[j] == perm[i + N][j];
    isBad[i + N] = all;
  }
  dp[0][N] = true;
  for (int i = 0; i < k; ++i)
    for (int j = -k; j <= k; ++j)
      if (!isBad[j + N]) {
        dp[i + 1][j + N + 1] |= dp[i][j + N];
        dp[i + 1][j + N - 1] |= dp[i][j + N];
      }
  for (int i = -k; i <= k; ++i)
    if (dp[k][i + N] && isBad[i + N]) {
      cout << "YES";
      return 0;
    }
  cout << "NO";
  return 0;
}
