#include <bits/stdc++.h>
using namespace std;
int p[105], pt[105], q[105], s[105], st[105];
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]);
  int flag = 0, flag2 = 0;
  for (int i = 1; i <= n; i++) p[i] = i;
  int f = 1;
  for (int j = 1; j <= n; j++)
    if (p[j] != s[j]) f = 0;
  if (f) {
    puts("NO");
    return 0;
  }
  for (int i = 1; i <= k; i++) {
    for (int j = 1; j <= n; j++) pt[j] = p[q[j]];
    for (int j = 1; j <= n; j++) p[j] = pt[j];
    int f = 1;
    for (int j = 1; j <= n; j++)
      if (p[j] != s[j]) f = 0;
    if (f && k != 1 && i == 1) flag2 = 1;
    if ((k - i) % 2 == 0) flag |= f;
  }
  for (int i = 1; i <= n; i++) p[i] = i;
  for (int i = 1; i <= k; i++) {
    for (int j = 1; j <= n; j++) pt[q[j]] = p[j];
    for (int j = 1; j <= n; j++) p[j] = pt[j];
    int f = 1;
    for (int j = 1; j <= n; j++)
      if (p[j] != s[j]) f = 0;
    if (f && k != 1 && i == 1 && flag2 == 1) {
      puts("NO");
      return 0;
    }
    if ((k - i) % 2 == 0) flag |= f;
  }
  puts(flag ? "YES" : "NO");
  return 0;
}
