#include <bits/stdc++.h>
using namespace std;
const double eps = 1e-9;
const double PI = acos(-1.0);
const int INF = 1e9 + 7;
const int N = int(2e5 + 7);
int n, k, p[107], p2[107], a[107], b[107], second[107], forw = INF, back = INF;
void no() {
  puts("NO");
  exit(0);
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cin >> n >> k;
  for (int i = 1; i <= n; i++) cin >> p[i];
  bool ok = 1;
  for (int i = 1; i <= n; i++) {
    cin >> second[i];
    if (second[i] != i) ok = 0;
  }
  if (ok) no();
  for (int i = 1; i <= n; i++) a[i] = i;
  for (int j = 1; j <= k; j++) {
    for (int i = 1; i <= n; i++) b[i] = a[p[i]];
    bool same = 1;
    for (int i = 1; i <= n; i++) {
      if (b[i] != second[i]) same = 0;
      a[i] = b[i];
    }
    if (same) {
      forw = j;
      break;
    }
  }
  for (int i = 1; i <= n; i++) a[i] = i;
  for (int j = 1; j <= k; j++) {
    for (int i = 1; i <= n; i++) b[p[i]] = a[i];
    bool same = 1;
    for (int i = 1; i <= n; i++) {
      if (b[i] != second[i]) same = 0;
      a[i] = b[i];
    }
    if (same) {
      back = j;
      break;
    }
  }
  if (back == k || forw == k ||
      ((back != 1 || forw != 1) && forw < k && forw % 2 == k % 2) ||
      ((back != 1 || forw != 1) && back < k && back % 2 == k % 2))
    puts("YES");
  else
    no();
  return 0;
}
