#include <bits/stdc++.h>
using namespace std;
int n, k;
vector<int> q[2], p;
int main() {
  scanf("%d %d", &n, &k);
  p.resize(n);
  for (int i = 0; i < 2; ++i) {
    q[i].resize(n);
    for (int j = 0; j < n; ++j) {
      scanf("%d", &q[i][j]);
      --q[i][j];
    }
  }
  iota(p.begin(), p.end(), 0);
  if (p == q[1]) {
    puts("NO");
    return 0;
  }
  int hcnt = 0, tcnt = 0;
  for (; hcnt <= k && q[1] != p; ++hcnt) {
    vector<int> tmp = p;
    for (int i = 0; i < n; ++i) p[i] = tmp[q[0][i]];
  }
  iota(p.begin(), p.end(), 0);
  for (; tcnt <= k && q[1] != p; ++tcnt) {
    vector<int> tmp = p;
    for (int i = 0; i < n; ++i) p[q[0][i]] = tmp[i];
  }
  if (tcnt == 1 && hcnt == 1 && tcnt != k && hcnt != k)
    puts("NO");
  else if (tcnt <= k && ((k - tcnt) % 2 == 0))
    puts("YES");
  else if (hcnt <= k && ((k - hcnt) % 2 == 0))
    puts("YES");
  else
    puts("NO");
}
