#include <bits/stdc++.h>
using namespace std;
const int MAXN = 100 + 10;
int a[2][MAXN], q[MAXN], s[MAXN];
vector<int> ans;
bool check(int n) {
  for (int i = 1; i <= n; i++) (void)0;
  for (int i = 1; i <= n; i++)
    if (a[1][i] != s[i]) return false;
  return true;
}
int main() {
  int n, k;
  scanf("%d%d", &n, &k);
  for (int i = 1; i <= n; i++) scanf("%d", q + i);
  for (int i = 1; i <= n; i++) scanf("%d", s + i);
  for (int i = 1; i <= n; i++) a[0][i] = a[1][i] = i;
  if (check(n)) {
    puts("NO");
    return 0;
  }
  bool b1 = false, b2 = false;
  for (int i = 0; i < k; i++) {
    for (int j = 1; j <= n; j++) {
      a[1][j] = a[0][q[j]];
    }
    if (check(n)) {
      if (!i) {
        b1 = true;
      }
      ans.push_back(i + 1);
    }
    for (int j = 1; j <= n; j++) a[0][j] = a[1][j];
  }
  for (int i = 1; i <= n; i++) a[0][i] = i;
  for (int i = 0; i < k; i++) {
    for (int j = 1; j <= n; j++) {
      a[1][q[j]] = a[0][j];
    }
    if (check(n)) {
      if (!i && k != 1) {
        b2 = true;
      }
      ans.push_back(i + 1);
    }
    for (int j = 1; j <= n; j++) a[0][j] = a[1][j];
  }
  if (b1 && b2 && k != 1) {
    puts("NO");
    return 0;
  }
  for (int x : ans) {
    if (x % 2 == k % 2) {
      puts("YES");
      return 0;
    }
  }
  puts("NO");
  return 0;
}
