#include <bits/stdc++.h>
using namespace std;
int n, k;
int a[102], b[102], c[2][102];
bool check(int x) {
  for (int i = 1; i <= n; ++i)
    if (c[x][i] != b[i]) return false;
  return true;
}
int main() {
  int t = 0;
  cin >> n >> k;
  for (int i = 1; i <= n; ++i) cin >> a[i], c[0][i] = i;
  for (int i = 1; i <= n; ++i) cin >> b[i];
  int move = -1, move2 = -1;
  bool flag = false;
  for (int i = 0; i <= k; ++i) {
    if (check(t)) {
      move = i;
      break;
    }
    t ^= 1;
    for (int j = 1; j <= n; ++j) c[t][j] = c[t ^ 1][a[j]];
  }
  for (int i = 1; i <= n; ++i) c[t][i] = i;
  for (int i = 0; i <= k; ++i) {
    if (check(t)) {
      move2 = i;
      break;
    }
    t ^= 1;
    for (int j = 1; j <= n; ++j) c[t][a[j]] = c[t ^ 1][j];
  }
  if (move == -1) move = k + 1;
  if (move2 == -1) move2 = k + 1;
  if (move == k || move2 == k) {
    puts("YES");
    return 0;
  }
  if (move < k && (move & 1) == (k & 1) && move + move2 > 2) {
    puts("YES");
    return 0;
  }
  if (move2 < k && (move2 & 1) == (k & 1) && move + move2 > 2) {
    puts("YES");
    return 0;
  }
  puts("NO");
  return 0;
}
