#include <bits/stdc++.h>
using namespace std;
long long int n, k, a[105], b[105], c[105], ai[105];
map<long long int, long long int> pos;
void apply_f(long long int c[105]) {
  for (int i = 1; i <= n; i++) c[i] = a[c[i]];
}
void apply_if(long long int c[105]) {
  for (int i = 1; i <= n; i++) c[i] = ai[c[i]];
}
bool compare(long long int a1[105], long long int a2[105]) {
  for (int i = 1; i <= n; i++)
    if (a1[i] != a2[i]) return 0;
  return 1;
}
bool Check(int l, int r) {
  if (l == 0 || l > k) return 0;
  if ((k - l) % 2 == 1) return 0;
  if (l == 1 && k != 1 && r == 1) return 0;
  return 1;
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cin >> n >> k;
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
    ai[a[i]] = i;
    c[i] = i;
  }
  for (int i = 1; i <= n; i++) {
    cin >> b[i];
  }
  long long int loc = 0;
  for (int i = 0; i <= 100; i++) {
    if (compare(c, b)) {
      pos[i] = 1;
    }
    apply_f(c);
  }
  for (int i = 1; i <= n; i++) c[i] = i;
  for (int i = 0; i <= 100; i++) {
    if (compare(c, b)) {
      pos[-i] = 1;
    }
    apply_if(c);
  }
  long long int R = 0, L = 0;
  for (int i = 0; i <= 100; i++) {
    if (pos[i]) {
      R = i;
      break;
    }
  }
  for (int i = 0; i >= -100; i--) {
    if (pos[i]) {
      L = -i;
      break;
    }
  }
  if (Check(L, R) || Check(R, L))
    cout << "YES" << '\n';
  else
    cout << "NO" << '\n';
  return 0;
}
