#include <bits/stdc++.h>
using namespace std;
int n, k;
int p[110], q[110];
int ed[110];
int t[110];
void heads() {
  for (int i = 1; i <= n; i++) t[i] = p[q[i]];
  for (int i = 1; i <= n; i++) p[i] = t[i];
}
void tails() {
  for (int i = 1; i <= n; i++) t[q[i]] = p[i];
  for (int i = 1; i <= n; i++) p[i] = t[i];
}
bool judge() {
  for (int i = 1; i <= n; i++)
    if (p[i] != ed[i]) return 0;
  return 1;
}
int main() {
  cin >> n >> k;
  for (int i = 1; i <= n; i++) cin >> q[i];
  for (int i = 1; i <= n; i++) cin >> ed[i];
  int flag = 0;
  for (int i = 1; i <= n; i++) p[i] = i;
  if (judge()) {
    if (k == 0)
      flag = 1;
    else
      flag = -1;
  }
  if (flag) {
    if (flag == 1)
      printf("YES\n");
    else
      printf("NO\n");
    return 0;
  }
  for (int i = 1; i <= n; i++) p[i] = i;
  for (int i = 1; i <= k; i++) {
    heads();
    if (judge()) {
      if (i == 1) {
        if (k == 1) {
          flag = 1;
          break;
        }
        tails();
        tails();
        if (judge()) {
          break;
        }
        heads();
        heads();
      }
      if ((k - i) % 2 == 0) {
        flag = 1;
        break;
      }
    }
  }
  if (flag) {
    if (flag == 1)
      printf("YES\n");
    else
      printf("NO\n");
    return 0;
  }
  for (int i = 1; i <= n; i++) p[i] = i;
  for (int i = 1; i <= k; i++) {
    tails();
    if (judge()) {
      if (i == 1) {
        if (k == 1) {
          flag = 1;
          break;
        }
        heads();
        heads();
        if (judge()) {
          break;
        }
        tails();
        tails();
      }
      if ((k - i) % 2 == 0) {
        flag = 1;
        break;
      }
    }
  }
  if (flag) {
    if (flag == 1)
      printf("YES\n");
    else
      printf("NO\n");
    return 0;
  }
  if (flag == 1)
    printf("YES\n");
  else
    printf("NO\n");
}
