#include <bits/stdc++.h>
using namespace std;
const long long N = 1e5 + 7;
int 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 check() {
  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 (check() && m != 0) {
    printf("NO\n");
    return 0;
  }
  int f = 1, cot1 = 0, cot2 = 0;
  for (int i = 1; i <= m; i++) {
    cal();
    if (check()) {
      cot1 = i;
      break;
    }
  }
  for (int i = 1; i <= n; i++) a[i] = i;
  for (int i = 1; i <= n; i++) swap(d[i], p[i]);
  for (int i = 1; i <= m; i++) {
    cal();
    if (check()) {
      cot2 = i;
      break;
    }
  }
  if (cot1 == 0 && cot2 == 0) {
    f = 0;
  } else if (m > 1 && cot1 == 1 && cot2 == 1) {
    f = 0;
  } else if ((m - cot1) % 2 && (m - cot2) % 2) {
    f = 0;
  } else if (((m - cot1) % 2 && cot2 == 0) || ((m - cot2) % 2 && cot1 == 0)) {
    f = 0;
  }
  printf("%s\n", f ? "YES" : "NO");
  return 0;
}
