#include <bits/stdc++.h>
using namespace std;
int pp[1010], p[1010];
int q[1010], s[1010];
int main() {
  int n, k;
  scanf("%d%d", &n, &k);
  for (int i = 1; i <= n; i++) cin >> q[i];
  for (int i = 1; i <= n; i++) cin >> s[i];
  for (int i = 1; i <= n; i++) pp[i] = p[i] = i;
  int flag;
  int xun1 = 0;
  while (xun1 <= k) {
    flag = 1;
    for (int i = 1; i <= n; i++) {
      if (pp[i] != s[i]) flag = 0;
    }
    if (flag) break;
    for (int i = 1; i <= n; i++) pp[i] = p[q[i]];
    for (int i = 1; i <= n; i++) {
      p[i] = pp[i];
    }
    xun1++;
  }
  for (int i = 1; i <= n; i++) pp[i] = p[i] = i;
  int xun2 = 0;
  while (xun2 <= k) {
    flag = 1;
    for (int i = 1; i <= n; i++) {
      if (pp[i] != s[i]) flag = 0;
    }
    if (flag) break;
    for (int i = 1; i <= n; i++) pp[q[i]] = p[i];
    for (int i = 1; i <= n; i++) p[i] = pp[i];
    xun2++;
  }
  if (xun1 == 0 || xun2 == 0)
    printf("NO\n");
  else if (k == 1 && (xun1 == 1 || xun2 == 1))
    printf("YES\n");
  else if (k != 1 && xun1 == 1 && xun2 == 1)
    printf("NO\n");
  else if (xun1 == k + 1 && xun2 == k + 1)
    printf("NO\n");
  else if ((xun1 - k) % 2 == 0 && xun1 <= k)
    printf("YES\n");
  else if ((xun2 - k) % 2 == 0 && xun2 <= k)
    printf("YES\n");
  else
    printf("NO\n");
  return 0;
}
