#include <bits/stdc++.h>
using namespace std;
int num1[110];
int num2[110];
int num[110];
int tmp[110];
int tra[110];
int n, k;
bool cal(int *num1, int *num2, int n) {
  for (int i = 1; i <= n; i++)
    if (num1[i] != num2[i]) return false;
  return true;
}
void fun(int *num, int *tra, int n) {
  for (int i = 1; i <= n; i++) tmp[i] = num[tra[i]];
  for (int i = 1; i <= n; i++) num[i] = tmp[i];
}
int main() {
  scanf("%d%d", &n, &k);
  for (int i = 1; i <= n; i++) scanf("%d", &tra[i]);
  for (int i = 1; i <= n; i++) num2[i] = i;
  for (int i = 1; i <= n; i++) scanf("%d", &num1[i]);
  if (cal(num1, num2, n)) {
    printf("NO\n");
    return 0;
  }
  int ans1 = 0;
  int ans2 = 0;
  for (int i = 1; i <= n; i++) num[i] = num1[i];
  for (int i = 1; i <= k; i++) {
    fun(num, tra, n);
    bool flag = cal(num, num2, n);
    if (flag) {
      ans1 = i;
      break;
    }
  }
  for (int i = 1; i <= n; i++) num[i] = num2[i];
  for (int i = 1; i <= k; i++) {
    fun(num, tra, n);
    bool flag = cal(num, num1, n);
    if (flag) {
      ans2 = i;
      break;
    }
  }
  bool flag = false;
  if (k != 1 && ans1 == 1 && ans2 == 1)
    flag = false;
  else if (ans1 >= 1 && ans1 % 2 == k % 2)
    flag = true;
  else if (ans2 >= 1 && ans2 % 2 == k % 2)
    flag = true;
  else
    flag = false;
  if (flag)
    printf("YES\n");
  else
    printf("NO\n");
}
