#include <bits/stdc++.h>
int s[110], q[110], n, k, a[110], b[110];
void gao1() {
  for (int i = 1; i <= n; ++i) b[i] = a[q[i]];
  for (int i = 1; i <= n; ++i) a[i] = b[i];
}
void gao2() {
  for (int i = 1; i <= n; ++i) b[q[i]] = a[i];
  for (int i = 1; i <= n; ++i) a[i] = b[i];
}
bool sam() {
  for (int i = 1; i <= n; ++i)
    if (a[i] ^ s[i]) return false;
  return true;
}
bool spj() {
  for (int i = 1; i <= n; ++i) a[i] = i;
  gao1();
  if (!sam()) return false;
  for (int i = 1; i <= n; ++i) a[i] = i;
  gao2();
  if (!sam()) return false;
  return true;
}
bool ok1() {
  for (int i = 1; i <= n; ++i) a[i] = i;
  if (sam()) return false;
  for (int i = 1; i <= k; ++i) {
    gao1();
    if (!sam()) continue;
    if ((k - i) & 1) return false;
    return true;
  }
  return false;
}
bool ok2() {
  for (int i = 1; i <= n; ++i) a[i] = i;
  if (sam() && k != 0) return false;
  for (int i = 1; i <= k; ++i) {
    gao2();
    if (!sam()) continue;
    if ((k - i) & 1) return false;
    return true;
  }
  return false;
}
int main() {
  scanf("%d %d", &n, &k);
  for (int i = 1; i <= n; ++i) a[i] = i;
  for (int i = 1; i <= n; ++i) scanf("%d", &q[i]);
  for (int i = 1; i <= n; ++i) scanf("%d", &s[i]);
  if ((!ok1()) && (!ok2()))
    puts("NO");
  else if (spj() && k != 1)
    puts("NO");
  else
    puts("YES");
  return 0;
}
