#include <bits/stdc++.h>
using namespace std;
const int maxn = 110;
int n, k;
int q[maxn], s[maxn], p[maxn];
int tmp[maxn];
int main() {
  cin >> n >> k;
  for (int i = 1; i <= n; i++) p[i] = i;
  for (int i = 1; i <= n; i++) scanf("%d", &q[i]);
  bool flag = true;
  for (int i = 1; i <= n; i++) {
    scanf("%d", &s[i]);
    if (s[i] != i) flag = false;
  }
  if (flag) {
    cout << "NO" << endl;
    return 0;
  }
  for (int i = 1; i <= n; i++) p[i] = i;
  int k1 = 0, k2 = 0;
  bool flag1 = false;
  while (1) {
    for (int i = 1; i <= n; i++) {
      tmp[i] = p[q[i]];
    }
    k1++;
    bool f = true;
    for (int i = 1; i <= n; i++) {
      p[i] = tmp[i];
      if (p[i] != s[i]) f = false;
    }
    if (f) {
      flag1 = true;
      break;
    }
    if (k1 == k) break;
  }
  bool flag2 = false;
  for (int i = 1; i <= n; i++) p[i] = i;
  while (1) {
    for (int i = 1; i <= n; i++) {
      tmp[q[i]] = p[i];
    }
    k2++;
    bool f = true;
    for (int i = 1; i <= n; i++) {
      p[i] = tmp[i];
      if (p[i] != s[i]) f = false;
    }
    if (f) {
      flag2 = true;
      break;
    }
    if (k2 == k) break;
  }
  if (!flag1 && !flag2) {
    cout << "NO" << endl;
    return 0;
  }
  if (k1 == 1 && k2 == 1) {
    if (k == 1)
      cout << "YES" << endl;
    else
      cout << "NO" << endl;
    return 0;
  }
  if (k < min(k1, k2)) {
    cout << "NO" << endl;
    return 0;
  }
  if ((flag1 && (k - k1) % 2 == 0) || (flag2 && (k - k2) % 2 == 0)) {
    cout << "YES" << endl;
    return 0;
  }
  cout << "NO" << endl;
  return 0;
}
