#include <bits/stdc++.h>
using namespace std;
int n, k;
vector<int> q, s, p[205];
map<vector<int>, int> cnt;
void build(int id) {
  p[id].resize(n);
  for (int i = 0; i < n; i++) {
    p[id][i] = i;
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cin >> n >> k;
  q.resize(n);
  s.resize(n);
  for (int i = 0; i < n; i++) {
    cin >> q[i];
    q[i]--;
  }
  for (int i = 0; i < n; i++) {
    cin >> s[i];
    s[i]--;
  }
  build(0);
  for (int d = 1; d <= k; d++) {
    p[d].resize(n);
    for (int i = 0; i < n; i++) {
      p[d][q[i]] = p[d - 1][i];
    }
  }
  reverse(p, p + k + 1);
  for (int d = k + 1; d <= 2 * k; d++) {
    p[d].resize(n);
    for (int i = 0; i < n; i++) {
      p[d][i] = p[d - 1][q[i]];
    }
  }
  bool ada = false;
  for (int d = k; d >= 0; d--) {
    cnt[p[d]]++;
    if (d == k) continue;
    if (d % 2 == 0) {
      ada |= p[d] == s && cnt[s] == 1 &&
             ((k - d == 1 && d != 0) ? p[k + 1] != s : true);
    }
  }
  cnt.clear();
  for (int d = k; d <= 2 * k; d++) {
    cnt[p[d]]++;
    if (d == k) continue;
    if (d % 2 == 0) {
      ada |= p[d] == s && cnt[s] == 1 &&
             ((d - k == 1 && d != 0) ? p[k - 1] != s : true);
    }
  }
  cout << (ada ? "YES\n" : "NO\n");
  return 0;
}
