#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll INF = static_cast<ll>(1e9) + 7;
const int MAXN = static_cast<int>(1e6) + 17;
int n, k;
int q[MAXN], r[MAXN], s[MAXN], p[MAXN];
bool read() {
  if (!(cin >> n >> k)) return false;
  for (ll i = 0; i < (ll)(n); ++i) cin >> q[i];
  for (ll i = 0; i < (ll)(n); ++i) cin >> s[i];
  return true;
}
void solve() {
  for (ll i = 0; i < (ll)(n); ++i) {
    p[i] = i;
    --q[i];
    --s[i];
  }
  for (ll i = 0; i < (ll)(n); ++i) r[q[i]] = i;
  bool kok = true;
  for (ll i = 0; i < (ll)(n); ++i)
    if (s[i] != i) kok = false;
  if (kok) {
    cout << "NO\n";
    return;
  }
  int lf = 0, rg = 0;
  for (int pw = 1; pw <= k + 1; ++pw) {
    for (int i = 0; i < n; ++i) p[i] = q[p[i]];
    bool kok = true;
    for (int i = 0; i < n; ++i)
      if (s[i] != p[i]) kok = false;
    rg = pw;
    if (kok) break;
  }
  for (int i = 0; i < n; ++i) p[i] = i;
  for (int pw = -1; pw >= -k - 1; --pw) {
    for (int i = 0; i < n; ++i) p[i] = r[p[i]];
    bool kok = true;
    for (int i = 0; i < n; ++i)
      if (s[i] != p[i]) kok = false;
    lf = pw;
    if (kok) break;
  }
  if (lf == -k || rg == k) {
    cout << "YES\n";
    return;
  }
  if (lf > -k && (rg > 1 || lf < -1) && (k + lf) % 2 == 0) {
    cout << "YES\n";
    return;
  }
  if (rg < k && (rg > 1 || lf < -1) && (k - rg) % 2 == 0) {
    cout << "YES\n";
    return;
  }
  cout << "NO\n";
}
int main() {
  cin.tie(nullptr);
  std::ios_base::sync_with_stdio(false);
  std::mt19937 rand('S' + 'E' + 'R' + 'E' + 'Z' + 'H' + 'K' + 'A');
  while (read()) solve();
  return 0;
}
