#include <bits/stdc++.h>
using namespace std;
int Set(int N, int pos) { return N = N | (1 << pos); }
int reset(int N, int pos) { return N = N & ~(1 << pos); }
bool check(int N, int pos) { return (bool)(N & (1 << pos)); }
void CI(int &_x) { scanf("%d", &_x); }
void CO(int &_x) { cout << _x; }
template <typename T>
void getarray(T a[], int n) {
  for (int i = 0; i < n; i++) cin >> a[i];
}
template <typename T>
void printarray(T a[], int n) {
  for (int i = 0; i < n - 1; i++) cout << a[i] << " ";
  cout << a[n - 1] << endl;
}
const double EPS = 1e-9;
const int INF = 0x7f7f7f7f;
int dr8[8] = {1, -1, 0, 0, 1, -1, -1, 1};
int dc8[8] = {0, 0, -1, 1, 1, 1, -1, -1};
int dr4[4] = {0, 0, 1, -1};
int dc4[4] = {-1, 1, 0, 0};
int kn8r[8] = {1, 2, 2, 1, -1, -2, -2, -1};
int kn8c[8] = {2, 1, -1, -2, -2, -1, 1, 2};
int q[105], des[105], p[105], temp[105], keep[105], keep2[105];
int n, k;
void operation1() {
  for (int i = 1; i <= n; i++) {
    temp[i] = keep2[q[i]];
  }
  for (int i = 1; i <= n; i++) {
    keep2[i] = temp[i];
  }
}
void operation2() {
  for (int i = 1; i <= n; i++) {
    temp[q[i]] = keep[i];
  }
  for (int i = 1; i <= n; i++) {
    keep[i] = temp[i];
  }
}
bool equall(int *a1, int *a2) {
  for (int i = 1; i <= n; i++)
    if (a1[i] != a2[i]) return 0;
  return 1;
}
int main() {
  cin >> n >> k;
  for (int i = 1; i <= n; i++) {
    cin >> q[i];
    p[i] = i;
    keep[i] = i;
    keep2[i] = i;
  }
  for (int i = 1; i <= n; i++) {
    cin >> des[i];
  }
  if (equall(des, p)) {
    puts("NO");
    return 0;
  }
  bool found1 = 0, found2 = 0;
  int cnt1 = 0;
  for (int i = 1; i <= k; i++) {
    cnt1++;
    operation1();
    if (equall(des, keep2)) {
      found1 = 1;
      break;
    }
  }
  int cnt2 = 0;
  for (int i = 1; i <= k; i++) {
    cnt2++;
    operation2();
    if (equall(des, keep)) {
      found2 = 1;
      break;
    }
  }
  if ((found1 == 0 && found2 == 0)) {
    puts("NO");
    return 0;
  }
  if (found1 && found2 && cnt1 == 1 && cnt2 == 1) {
    if (k > 1) {
      puts("NO");
      return 0;
    }
  }
  if (found1 && (k - cnt1) % 2 == 0) {
    puts("YES");
  } else if (found2 && (k - cnt2) % 2 == 0) {
    puts("YES");
  } else
    puts("NO");
}
