#include <bits/stdc++.h>
using namespace std;
int p[105];
int s[105];
int q[2][105];
int n, m;
int check(int x) {
  for (int i = 1; i <= n; i++)
    if (q[x][i] != s[i]) return 0;
  return 1;
}
int main() {
  ios::sync_with_stdio(0);
  cin >> n >> m;
  for (int i = 1; i <= n; i++) {
    cin >> p[i];
    q[0][i] = i;
  }
  for (int i = 1; i <= n; i++) cin >> s[i];
  int l = 0, r = 0, t = 1, f = 1;
  if (check(0)) f = 0;
  for (int i = 1; i <= m; i++) {
    for (int j = 1; j <= n; j++) q[t][j] = q[t ^ 1][p[j]];
    if (check(t)) {
      r = i;
      break;
    }
    t ^= 1;
  }
  for (int i = 1; i <= n; i++) q[0][i] = i;
  t = 1;
  for (int i = 1; i <= m; i++) {
    for (int j = 1; j <= n; j++) q[t][p[j]] = q[t ^ 1][j];
    if (check(t)) {
      l = i;
      break;
    }
    t ^= 1;
  }
  if (l == 0 && r == 0)
    f = 0;
  else if (m > 1 && l == 1 && r == 1)
    f = 0;
  else if ((m - l) % 2 && (m - r) % 2)
    f = 0;
  else if (((m - l) % 2 && r == 0) || ((m - r) % 2 && l == 0))
    f = 0;
  if (f)
    cout << "YES" << endl;
  else
    cout << "NO" << endl;
}
