#include <bits/stdc++.h>
using namespace std;
int chh;
const int N = 105;
int n, k;
int q[N], s[N], a[N], b[N];
int main() {
  int t1, t2, t;
  bool flag;
  while (~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;
    flag = 0;
    for (int i = (1); i <= (n); i++) {
      if (s[i] != i) {
        flag = 1;
        break;
      }
    }
    if (!flag) {
      puts("NO");
      continue;
    }
    t1 = t2 = -1;
    for (int i = (1); i <= (100); i++) {
      for (int j = (1); j <= (n); j++) b[j] = a[q[j]];
      memcpy(a, b, sizeof(b));
      flag = 1;
      for (int j = (1); j <= (n); j++) {
        if (a[j] != s[j]) {
          flag = 0;
          break;
        }
      }
      if (flag) {
        t1 = i;
        break;
      }
    }
    for (int i = (1); i <= (n); i++) a[i] = i;
    for (int i = (1); i <= (100); i++) {
      for (int j = (1); j <= (n); j++) b[q[j]] = a[j];
      memcpy(a, b, sizeof(b));
      flag = 1;
      for (int j = (1); j <= (n); j++) {
        if (a[j] != s[j]) {
          flag = 0;
          break;
        }
      }
      if (flag) {
        t2 = i;
        break;
      }
    }
    if (t1 == -1 && t2 == -1)
      puts("NO");
    else if (t1 + t2 == 2)
      puts(k == 1 ? "YES" : "NO");
    else {
      if (k < t1 && k < t2)
        puts("NO");
      else {
        if (t1 != -1 && k >= t1 && ((k - t1) % 2 == 0))
          puts("YES");
        else if (t2 != -1 && k >= t2 && ((k - t2) % 2 == 0))
          puts("YES");
        else
          puts("NO");
      }
    }
  }
  return 0;
}
