#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:256000000")
using namespace std;
const long long MAXN = (long long)1e5 + 7;
const long long INF = (long long)1e9 + 7;
const long long LINF = (long long)2e18 + 7;
vector<int> Q, S;
bool eq(vector<int> &a, vector<int> &b) {
  for (int i = 0; i < a.size(); i++)
    if (a[i] != b[i]) return 0;
  return 1;
}
int main() {
  iostream::sync_with_stdio(false);
  cin.tie(0);
  int N, K;
  cin >> N >> K;
  for (int i = 0; i < N; i++) {
    int a;
    cin >> a;
    Q.push_back(a - 1);
  }
  for (int i = 0; i < N; i++) {
    int a;
    cin >> a;
    S.push_back(a - 1);
  }
  vector<int> Cur;
  for (int i = 0; i < N; i++) Cur.push_back(i);
  if (eq(S, Cur)) {
    cout << "NO\n";
    return 0;
  }
  vector<int> To, To1, To2;
  To1.resize(N);
  To2.resize(N);
  for (int i = 0; i < N; i++) To1[i] = Cur[Q[i]];
  for (int i = 0; i < N; i++) To2[Q[i]] = Cur[i];
  if (eq(To1, To2)) {
    if (K == 1)
      cout << "YES\n";
    else
      cout << "NO\n";
    return 0;
  }
  for (int t = 0; t < K; t++) {
    To.clear();
    To.resize(N);
    for (int i = 0; i < N; i++) To[Q[i]] = Cur[i];
    if (eq(To, S)) {
      if ((K - t - 1) % 2 == 0) {
        cout << "YES\n";
        return 0;
      }
      break;
    }
    Cur = To;
  }
  Cur.clear();
  for (int i = 0; i < N; i++) Cur.push_back(i);
  for (int t = 0; t < K; t++) {
    To.clear();
    To.resize(N);
    for (int i = 0; i < N; i++) To[i] = Cur[Q[i]];
    if (eq(To, S)) {
      if ((K - t - 1) % 2 == 0) {
        cout << "YES\n";
        return 0;
      }
      break;
    }
    Cur = To;
  }
  cout << "NO\n";
}
