#include <bits/stdc++.h>
using namespace std;
int i, i0, n, m, ans, p[105], a[105], b[105], d[105], c[105];
void cal() {
  for (int i = 1; i <= n; i++) {
    b[i] = a[p[i]];
  }
  for (int i = 1; i <= n; i++) {
    a[i] = b[i];
  }
}
bool chk() {
  for (int i = 1; i <= n; i++) {
    if (c[i] != a[i]) return 0;
  }
  return 1;
}
int main() {
  scanf("%d %d", &n, &m);
  for (int i = 1; i <= n; i++) scanf("%d", &p[i]), d[p[i]] = i, a[i] = i;
  for (int i = 1; i <= n; i++) scanf("%d", &c[i]);
  if (chk() && m != 0) {
    printf("NO\n");
    return 0;
  }
  bool f = 0, t = 1, tt = 1;
  for (int i = 1; i <= m; i++) {
    cal();
    if (i == 1 && chk()) {
      t = 0;
    }
  }
  for (int i = 1; i <= n; i++) swap(p[i], d[i]);
  for (int i = m - 2; i >= -m; i -= 2) {
    cal(), cal();
    if (i == -1 && chk()) tt = 0;
  }
  for (int i = 1; i <= n; i++) swap(p[i], d[i]);
  for (int i = -m; i <= m; i += 2, cal(), cal()) {
    if (chk()) {
      if (t || tt || m == 1 || m == -1) f = 1;
    }
  }
  printf("%s\n", f ? "YES" : "NO");
  return 0;
}
