#include <bits/stdc++.h>
using namespace std;
int n, mx, t, h1, h2, h3, k, v[1000], vno[1000];
vector<int> q, s;
bool check(vector<int>& ts, vector<int>& s) {
  for (int fh1 = 0; fh1 < ts.size(); fh1++)
    if (ts[fh1] != s[fh1]) return 0;
  return 1;
}
vector<vector<int> > vv;
int main() {
  while (~scanf("%d%d", &n, &k)) {
    q.clear();
    s.clear();
    vector<int> iq(n, 0);
    for (h1 = 0; h1 < n; h1++) {
      scanf("%d", &h2);
      h2--;
      q.push_back(h2);
      iq[h2] = h1;
    }
    vector<int> x(n, 0);
    for (h1 = 0; h1 < n; h1++) {
      scanf("%d", &h2);
      h2--;
      s.push_back(h2);
      x[h1] = h1;
    }
    if (check(x, s)) {
      cout << (k ? "NO" : "YES") << endl;
      continue;
    }
    if (check(q, s)) {
      if (k == 1) {
        cout << "YES" << endl;
        continue;
      }
      if (check(iq, s)) {
        cout << "NO" << endl;
        continue;
      }
    }
    memset(v, -1, sizeof(v));
    vv.clear();
    int vp = 0;
    for (h1 = 0; h1 < n; h1++) {
      if (v[h1] == -1) {
        int no = 0;
        vv.push_back(vector<int>());
        for (h2 = h1; !~v[h2]; h2 = q[h2]) {
          v[h2] = vp;
          vv[vp].push_back(h2);
          vno[h2] = no++;
        }
        vp++;
      }
    }
    bool ans = 0;
    for (int kk = k; !ans && kk >= 0; kk -= 2) {
      for (int xx = 0; !ans && xx <= kk; xx++) {
        for (h1 = 0; h1 < n; h1++) {
          x[h1] = vv[v[h1]][(vno[h1] + xx + xx - kk + vv[v[h1]].size() * 200) %
                            vv[v[h1]].size()];
        }
        if (check(x, s)) ans = 1;
      }
    }
    cout << (ans ? "YES" : "NO") << endl;
  }
}
