#include <bits/stdc++.h>
using namespace std;
int n, k;
int p[120], q[120];
int s[120], t[120];
int S[120], T[120];
bool flag = true;
void head() {
  flag = true;
  for (int i = 0; i < n; i++) S[i] = s[p[i]];
  for (int i = 0; i < n; i++)
    s[i] = S[i], flag = flag && ((S[i] == q[i]) ? true : false);
}
void tail() {
  flag = true;
  for (int i = 0; i < n; i++) T[p[i]] = t[i];
  for (int i = 0; i < n; i++)
    t[i] = T[i], flag = flag && ((T[i] == q[i]) ? true : false);
}
int main() {
  cin >> n >> k;
  for (int i = 0; i < n; i++) cin >> p[i], p[i]--;
  for (int i = 0; i < n; i++) cin >> q[i], q[i]--;
  for (int i = 0; i < n; i++)
    if (q[i] != i) flag = false;
  if (flag) {
    cout << "NO";
    return 0;
  }
  flag = true;
  for (int i = 0; i < n; i++) s[i] = t[i] = i;
  int cthead = k + 1;
  for (int i = 0; i < k; i++) {
    head();
    if (flag) {
      cthead = i + 1;
      break;
    }
  }
  int cttail = k + 1;
  for (int i = 0; i < k; i++) {
    tail();
    if (flag) {
      cttail = i + 1;
      break;
    }
  }
  if (cthead == 1 and cttail == 1 and k == 1)
    flag = true;
  else if (cthead == 1 and cttail == 1 and k != 1)
    flag = false;
  else if (abs(k - cthead) % 2 == 0 || abs(k - cttail) % 2 == 0)
    flag = true;
  else
    flag = false;
  if (flag)
    cout << "YES" << endl;
  else
    cout << "NO" << endl;
  return 0;
}
