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