#include <bits/stdc++.h>
using namespace std;
int n, k;
int p1[100];
int inv_p1[100];
int p2[100];
int tmp[100], p[100];
int main() {
  scanf("%d %d", &n, &k);
  for (int i = 0; i < n; i++) scanf("%d", &p1[i]), p1[i]--;
  for (int i = 0; i < n; i++) scanf("%d", &p2[i]), p2[i]--;
  for (int i = 0; i < n; i++) inv_p1[p1[i]] = i;
  int lb = k + 1, ub = k + 1;
  for (int i = 0; i < n; i++) p[i] = i;
  for (int l = 0; l <= k; l++) {
    bool same = true;
    for (int i = 0; same && i < n; i++)
      if (p[i] != p2[i]) same = false;
    if (same) {
      lb = l;
      break;
    }
    for (int i = 0; i < n; i++) tmp[i] = p[p1[i]];
    for (int i = 0; i < n; i++) p[i] = tmp[i];
  }
  for (int i = 0; i < n; i++) p[i] = i;
  for (int l = 0; l <= k; l++) {
    bool same = true;
    for (int i = 0; same && i < n; i++)
      if (p[i] != p2[i]) same = false;
    if (same) {
      ub = l;
      break;
    }
    for (int i = 0; i < n; i++) tmp[i] = p[inv_p1[i]];
    for (int i = 0; i < n; i++) p[i] = tmp[i];
  }
  if (lb == 0 || ub == 0)
    printf("NO\n");
  else if (lb == 1) {
    if (k == 1)
      printf("YES\n");
    else if (ub == 1)
      printf("NO\n");
    else if (k % 2)
      printf("YES\n");
    else if (ub <= k && (k - ub) % 2 == 0)
      printf("YES\n");
    else
      printf("NO\n");
  } else if (ub == 1) {
    if (k % 2)
      printf("YES\n");
    else if (lb <= k && (k - lb) % 2 == 0)
      printf("YES\n");
    else
      printf("NO\n");
  } else {
    if (lb <= k && (k - lb) % 2 == 0)
      printf("YES\n");
    else if (ub <= k && (k - ub) % 2 == 0)
      printf("YES\n");
    else
      printf("NO\n");
  }
  return 0;
}
