#include <bits/stdc++.h>
using namespace std;
template <typename T>
inline T abs(T a) {
  return a < 0 ? (-a) : a;
}
template <typename T>
inline T sqr(T x) {
  return x * x;
}
vector<vector<int> > cls;
void BOLT() {
  cout << "NO" << endl;
  exit(0);
}
vector<int> q, v;
int n;
vector<int> Do1(vector<int> &p) {
  vector<int> v(n);
  for (int(i) = 0; (i) < (n); (i)++) {
    v[i] = p[q[i]];
  }
  return v;
}
vector<int> Do2(vector<int> &p) {
  vector<int> v(n);
  for (int(i) = 0; (i) < (n); (i)++) {
    v[q[i]] = p[i];
  }
  return v;
}
bool Check(vector<int> &p) {
  for (int(i) = 0; (i) < (n); (i)++) {
    if (p[i] != v[i]) {
      return false;
    }
  }
  return true;
}
int main() {
  int k;
  cin >> n >> k;
  q.resize(n);
  for (int(i) = 0; (i) < (n); (i)++) {
    cin >> q[i];
    q[i]--;
  }
  v.resize(n);
  for (int(i) = 0; (i) < (n); (i)++) {
    cin >> v[i];
    v[i]--;
  }
  for (int(aa) = 0; (aa) < (k + 1); (aa)++) {
    int a = aa;
    int b = k - a;
    vector<int> p(n);
    for (int(i) = 0; (i) < (n); (i)++) p[i] = i;
    bool ok = !Check(p);
    vector<int> t;
    while (a + b > 1) {
      int last = a + b;
      if (a + b > 1 && a) {
        t = Do1(p);
        if (!Check(t)) {
          p = t;
          a--;
        }
      }
      if (a + b > 1 && b) {
        t = Do2(p);
        if (!Check(t)) {
          p = t;
          b--;
        }
      }
      if (last == a + b) break;
    }
    if (a) p = Do1(p), a--;
    if (b) p = Do2(p), b--;
    if (ok && a + b == 0 && Check(p)) {
      cout << "YES" << endl;
      return 0;
    }
  }
  BOLT();
  return 0;
}
