#include <bits/stdc++.h>
using namespace std;
const long long INF = 0x3f3f3f3f3f3f3f3f;
const long long MAXN = 200 + 7;
const long long MAXM = 1e5 + 7;
const long long MOD = 1e9 + 7;
const double eps = 1e-6;
const double pi = acos(-1.0);
int p1[MAXN], p2[MAXN], q[MAXN], s[MAXN];
int n, k;
bool check(int p[], int x[]) {
  for (int i = 1; i <= n; i++)
    if (p[i] != x[i]) return false;
  return true;
}
int main() {
  while (~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++) p1[i] = p2[i] = i;
    int op1 = 0, op2 = 0;
    while (!check(p2, s)) {
      for (int i = 1; i <= n; i++) p2[q[i]] = p1[i];
      for (int i = 1; i <= n; i++) p1[i] = p2[i];
      op1++;
      if (op1 > k) break;
    }
    for (int i = 1; i <= n; i++) p2[i] = p1[i] = i;
    while (!check(p2, s)) {
      for (int i = 1; i <= n; i++) p2[i] = p1[q[i]];
      for (int i = 1; i <= n; i++) p1[i] = p2[i];
      op2++;
      if (op2 > k) break;
    }
    if (!op1 && !op2)
      puts("NO");
    else if (k == 1 && (op1 == 1 || op2 == 1))
      puts("YES");
    else if (k != 1 && op1 == 1 && op2 == 1)
      puts("NO");
    else if (op1 > k && op2 > k)
      puts("NO");
    else if ((op1 - k) % 2 == 0 && op1 <= k)
      printf("YES\n");
    else if ((op2 - k) % 2 == 0 && op2 <= k)
      printf("YES\n");
    else
      printf("NO\n");
  }
  return 0;
}
