#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, k, s[110], q[110], a[110], b[110], head = -1, tail = -1, f = 0;
  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++) {
    a[i] = i;
    if (a[i] != s[i]) f = 1;
  }
  if (f == 0) {
    printf("NO");
    return 0;
  }
  for (int i = 1; i <= k; i++) {
    int flag = 0;
    for (int j = 1; j <= n; j++) b[j] = a[q[j]];
    for (int j = 1; j <= n; j++) {
      a[j] = b[j];
      if (a[j] != s[j]) flag = 1;
    }
    if (flag == 0) {
      head = i;
      break;
    }
  }
  for (int i = 1; i <= n; i++) a[i] = i;
  for (int i = 1; i <= k; i++) {
    int flag = 0;
    for (int j = 1; j <= n; j++) b[q[j]] = a[j];
    for (int j = 1; j <= n; j++) {
      a[j] = b[j];
      if (a[j] != s[j]) flag = 1;
    }
    if (flag == 0) {
      tail = i;
      break;
    }
  }
  if (head == -1 && tail == -1)
    printf("NO");
  else if (head == 1 && tail == 1 && k != 1)
    printf("NO");
  else if ((k - head) % 2 == 0 && head != -1)
    printf("YES");
  else if ((k - tail) % 2 == 0 && tail != -1)
    printf("YES");
  else
    printf("NO");
  return 0;
}
