#include <bits/stdc++.h>
using namespace std;
const long long mod = 1e9 + 7;
const long long mx = 1600;
const long long inf = 1e9;
const int sz = 20;
int dx[4] = {-1, 0, 0, 1};
int dy[4] = {0, -1, 1, 0};
vector<string> vec(mx);
bool is_equal(vector<int>& a, vector<int>& b) {
  for (int i = 0; i < (int)a.size(); ++i)
    if (a[i] != b[i]) return false;
  return true;
}
void input() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  ;
  int n, k;
  cin >> n >> k;
  vector<int> q(n), s(n), p(n);
  for (int i = 0; i < n; ++i) cin >> q[i];
  for (int i = 0; i < n; ++i) cin >> s[i];
  for (int i = 0; i < n; ++i) p[i] = i + 1;
  if (is_equal(p, s)) {
    cout << "NO"
         << "\n";
    return;
  }
  vector<int> q_inv(n);
  for (int i = 0; i < n; ++i) q_inv[q[i] - 1] = i + 1;
  if (is_equal(q, q_inv)) {
    if (is_equal(s, q)) {
      if (k == 1)
        cout << "YES"
             << "\n";
      else
        cout << "NO"
             << "\n";
      return;
    }
  }
  int t = 1;
  while (t <= k) {
    vector<int> temp(n);
    for (int i = 0; i < n; ++i) {
      temp[i] = p[q[i] - 1];
    }
    if (is_equal(temp, s)) {
      if ((k - t) % 2 == 0) {
        cout << "YES"
             << "\n";
        return;
      }
      break;
    }
    for (int i = 0; i < n; ++i) p[i] = temp[i];
    ++t;
  }
  for (int i = 0; i < n; ++i) p[i] = i + 1;
  t = 1;
  while (t <= k) {
    vector<int> temp(n);
    for (int i = 0; i < n; ++i) {
      temp[i] = p[q_inv[i] - 1];
    }
    if (is_equal(temp, s)) {
      if ((k - t) % 2 == 0) {
        cout << "YES"
             << "\n";
        return;
      }
      break;
    }
    for (int i = 0; i < n; ++i) p[i] = temp[i];
    ++t;
  }
  cout << "NO"
       << "\n";
}
int main() {
  input();
  return 0;
}
