#include <bits/stdc++.h>
using namespace std;
const long long inf = INT_MAX, df = 305;
long long i, j, k, l, m, n, o, p, q, r, s, t, u, v, w, x, y, z, a[df], b[df],
    c[df], d[df], e[df];
inline long long read() {
  long long x = 0, y = 1;
  char ch = getchar();
  while (ch > '9' || ch < '0') y = (ch == '-') ? -1 : 1, ch = getchar();
  while (ch >= '0' && ch <= '9')
    x = (x << 3) + (x << 1) + ch - '0', ch = getchar();
  return x * y;
}
void solve(long long tag) {
  if (tag == 1) {
    for (long long i = (1); i <= (n); ++i) d[b[i]] = a[i];
    for (long long i = (1); i <= (n); ++i) a[i] = d[i];
    return;
  }
  if (tag == -1) {
    for (long long i = (1); i <= (n); ++i) d[i] = a[b[i]];
    for (long long i = (1); i <= (n); ++i) a[i] = d[i];
    return;
  }
  return;
}
bool chk() {
  for (long long i = (1); i <= (n); ++i)
    if (a[i] != c[i]) return 0;
  return 1;
}
int main() {
  n = read(), k = read();
  for (long long i = (1); i <= (n); ++i) a[i] = i, b[i] = read();
  for (long long i = (1); i <= (n); ++i) c[i] = read();
  if (chk()) return puts("NO"), 0;
  long long ty = 0, opg = 0, zy = 0;
  for (long long i = (1); i <= (n); ++i) e[i] = a[i];
  for (long long i = (1); i <= (k); ++i) {
    solve(1);
    if (chk()) {
      opg = 1;
      ty = i;
      break;
    }
  }
  for (long long i = (1); i <= (n); ++i) a[i] = e[i];
  for (long long i = (1); i <= (k); ++i) {
    solve(-1);
    if (chk()) {
      opg = 1;
      zy = i;
      break;
    }
  }
  if (ty == k || zy == k) return puts("YES"), 0;
  if (ty != 1 && zy != 1) {
    if (((k - ty) % 2 == 0 && ty != 0) || ((k - zy) % 2 == 0 && zy != 0))
      return puts("YES"), 0;
    return puts("NO"), 0;
  }
  if (ty != 1) {
    if ((k - zy) % 2 == 0 || ((k - ty) % 2 == 0 && ty != 0))
      return puts("YES"), 0;
    return puts("NO"), 0;
  }
  if (zy != 1) {
    if ((k - ty) % 2 == 0 || ((k - zy) % 2 == 0 && zy != 0))
      return puts("YES"), 0;
    return puts("NO"), 0;
  }
  if (ty == 1 && zy == 1) {
    if (k == 1) return puts("YES"), 0;
    return puts("NO"), 0;
  }
}
