#include <bits/stdc++.h>
using namespace std;
const long long mod = 1e9 + 7;
const int N = 1e2 + 5;
int p[N], a[N];
int aim[N];
int temp[N];
int main() {
  int n, k;
  while (cin >> n >> k) {
    for (int i = 1; i <= n; i++) {
      int x;
      scanf("%d", &x);
      a[i] = x;
    }
    for (int i = 1; i <= n; i++) scanf("%d", &aim[i]);
    int acnt = 0, bcnt = 0;
    for (int i = 1; i <= n; i++) p[i] = i;
    while (acnt <= k) {
      int flag = 1;
      for (int i = 1; i <= n; i++)
        if (p[i] != aim[i]) {
          flag = 0;
          break;
        }
      if (flag) break;
      acnt++;
      for (int i = 1; i <= n; i++) temp[i] = p[a[i]];
      for (int i = 1; i <= n; i++) p[i] = temp[i];
    }
    for (int i = 1; i <= n; i++) p[i] = i;
    while (bcnt <= k) {
      int flag = 1;
      for (int i = 1; i <= n; i++)
        if (p[i] != aim[i]) {
          flag = 0;
          break;
        }
      if (flag) break;
      bcnt++;
      for (int i = 1; i <= n; i++) temp[a[i]] = p[i];
      for (int i = 1; i <= n; i++) p[i] = temp[i];
    }
    if (k == 0) {
      if (acnt == 0 && bcnt == 0)
        printf("YES\n");
      else
        printf("NO\n");
      continue;
    }
    if (acnt == 0 && bcnt == 0 && k) {
      printf("NO\n");
      continue;
    }
    if (acnt > k && bcnt > k) {
      printf("NO\n");
      continue;
    }
    if (acnt == k || bcnt == k) {
      printf("YES\n");
      continue;
    }
    if (acnt == 1 && bcnt == 1) {
      printf("NO\n");
      continue;
    }
    if ((k - acnt) % 2 == 0 || (k - bcnt) % 2 == 0) {
      printf("YES\n");
      continue;
    }
    printf("NO\n");
  }
  return 0;
}
