#include <bits/stdc++.h>
using namespace std;
const long long mod7 = 1000000007;
const long long mod9 = 1000000009;
const int linf = 2000000000;
const long long llinf = 1000000000000000000ll;
ifstream in("series.in");
ofstream out("series.out");
int n;
vector<int> p, t, q, s, t1, t2;
void next() {
  for (int i = 1; i <= n; ++i) t[i] = p[q[i]];
  p = t;
}
void prev() {
  for (int i = 1; i <= n; ++i) t[q[i]] = p[i];
  p = t;
}
void print(vector<int> &a) {
  for (int i = 1; i <= n; ++i) cout << a[i] << ' ';
  cout << endl;
}
int main() {
  int k;
  cin >> n >> k;
  t.assign(n + 1, 0);
  p.assign(n + 1, 0);
  q.assign(n + 1, 0);
  s.assign(n + 1, 0);
  for (int i = 1; i <= n; ++i) {
    p[i] = i;
    cin >> q[i];
  }
  for (int i = 1; i <= n; ++i) {
    cin >> s[i];
  }
  if (s == p) {
    cout << "NO";
    return 0;
  }
  next();
  t1 = p;
  prev();
  prev();
  t2 = p;
  if (t1 == t2) {
    if (t1 == s && k == 1) {
      cout << "YES";
    } else {
      cout << "NO";
    }
    return 0;
  }
  next();
  int i = 0;
  for (; i < k; ++i) {
    next();
    if (p == s) {
      if ((k - i) & 1) {
        cout << "YES";
        return 0;
      } else
        break;
    }
  }
  if (i == k) --i;
  for (; i >= 0; --i) prev();
  for (int i = 0; i < k; ++i) {
    prev();
    if (p == s) {
      if ((k - i) & 1) {
        cout << "YES";
        return 0;
      } else
        break;
    }
  }
  cout << "NO";
  return 0;
}
