#include <bits/stdc++.h>
using namespace std;
const int MAXN = 105;
int p[MAXN], q[MAXN], n, s[MAXN], temp[MAXN], k;
bool ck() {
  for (int i = 1; i <= n; ++i) {
    if (s[i] != p[i]) return false;
  }
  return true;
}
void go() {
  for (int i = 1; i <= n; ++i) {
    temp[i] = p[q[i]];
  }
  for (int i = 1; i <= n; ++i) {
    p[i] = temp[i];
  }
  return;
}
void go2() {
  for (int i = 1; i <= n; ++i) {
    temp[q[i]] = p[i];
  }
  for (int i = 1; i <= n; ++i) {
    p[i] = temp[i];
  }
  return;
}
int main() {
  scanf("%d %d", &n, &k);
  for (int i = 1; i <= n; ++i) {
    scanf("%d", &q[i]);
  }
  for (int i = 1; i <= n; ++i) {
    scanf("%d", &s[i]);
  }
  for (int i = 1; i <= n; ++i) {
    p[i] = i;
  }
  if (ck()) {
    printf("NO\n");
    return 0;
  }
  int ans1 = -1;
  for (int i = 1; i <= k; ++i) {
    go();
    if (ck()) {
      ans1 = i;
      break;
    }
  }
  for (int i = 1; i <= n; ++i) {
    p[i] = i;
  }
  int ans2 = -1;
  for (int i = 1; i <= k; ++i) {
    go2();
    if (ck()) {
      ans2 = i;
      break;
    }
  }
  bool f = false;
  if (ans1 == 1 && ans2 == 1) {
    if (k == 1) {
      printf("YES\n");
    } else {
      printf("NO\n");
    }
    return 0;
  }
  if (ans1 != -1) {
    if ((k - ans1) % 2 == 0) f = true;
  }
  if (ans2 != -1) {
    if ((k - ans2) % 2 == 0) f = true;
  }
  if (f) {
    printf("YES\n");
  } else {
    printf("NO\n");
  }
  return 0;
}
