#include <bits/stdc++.h>
using namespace std;
template <typename T, typename TT>
ostream& operator<<(ostream& out, const pair<T, TT>& p) {
  out << p.first << " " << p.second;
  return out;
}
template <typename T, typename TT>
istream& operator>>(istream& in, pair<T, TT>& s) {
  in >> s.first >> s.second;
  return in;
}
vector<int> arr(200, 0);
vector<int> target(200, 0);
vector<int> trans(200, 0);
int n, k;
vector<int> change(vector<int>& vec, int status) {
  vector<int> temp(200, 0);
  vector<int> ret(200, 0);
  if (status) {
    for (int(i) = 1; (i) <= (n); ++(i)) {
      temp[i] = vec[trans[i]];
    }
    for (int(i) = 1; (i) <= (n); ++(i)) {
      ret[i] = temp[i];
    }
  } else {
    for (int(i) = 1; (i) <= (n); ++(i)) {
      temp[trans[i]] = vec[i];
    }
    for (int(i) = 1; (i) <= (n); ++(i)) {
      ret[i] = temp[i];
    }
  }
  return ret;
}
int done = 0;
void no() {
  if (!done) cout << "NO" << endl;
  done = 1;
}
void yes() {
  if (!done) cout << "YES" << endl;
  done = 1;
}
int main() {
  cin >> n >> k;
  for (int(i) = 1; (i) <= (n); ++(i)) {
    arr[i] = i;
  }
  for (int(i) = 1; (i) <= (n); ++(i)) {
    cin >> trans[i];
  }
  for (int(i) = 1; (i) <= (n); ++(i)) {
    cin >> target[i];
  }
  vector<int> working = arr;
  if (working == target) {
    no();
  }
  if (k == 1) {
    if (change(working, 1) == target || change(working, 0) == target) {
      yes();
    } else {
      no();
    }
  } else {
    if (change(working, 1) == target && change(working, 0) == target) {
      no();
    } else {
      {
        int index = -1;
        for (int(i) = 1; (i) <= (k); ++(i)) {
          working = change(working, 0);
          if (working == target) {
            index = i;
            break;
          }
        }
        if (index != -1) {
          if ((index - k) % 2 == 0) {
            yes();
          }
        }
      }
      {
        int index = -1;
        working = arr;
        for (int(i) = 1; (i) <= (k); ++(i)) {
          working = change(working, 1);
          if (working == target) {
            index = i;
            break;
          }
        }
        if (index != -1) {
          if ((index - k) % 2 == 0) {
            yes();
          }
        }
      }
    }
  }
  no();
  return 0;
}
