#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, k, i, j, l;
  int cq, cqi, ch;
  int f1, f2, fa, c = 0;
  int q[101], s[101], temp[101], local[101];
  cin >> n >> k;
  for (i = 1; i <= n; i++) cin >> q[i];
  for (i = 1; i <= n; i++) cin >> s[i];
  for (i = 1; i <= n; i++) {
    if (s[i] != i) {
      c = 1;
      break;
    }
  }
  fa = 0;
  for (i = 0; i <= k; i++) {
    cq = i;
    cqi = k - i;
    for (j = 1; j <= n; j++) temp[j] = j;
    f1 = 0;
    f2 = 0;
    if (cqi > cq) {
      cqi = cqi - cq;
      for (j = 1; j <= cqi; j++) {
        for (l = 1; l <= n; l++) local[q[l]] = temp[l];
        for (l = 1; l <= n; l++) temp[l] = local[l];
        if (j != cqi) {
          ch = 0;
          for (l = 1; l <= n; l++) {
            if (temp[l] != s[l]) {
              ch = 1;
              break;
            }
          }
          if (!ch) f1 = 1;
        }
      }
      for (j = 1; j <= n; j++) {
        if (temp[j] != s[j]) {
          f2 = 1;
          break;
        }
      }
      if (cqi == 1 && f2 == 0 && (k - i) > 1) {
        ch = 0;
        for (j = 1; j <= n; j++) temp[j] = j;
        for (l = 1; l <= n; l++) local[l] = temp[q[l]];
        for (l = 1; l <= n; l++) temp[l] = local[l];
        for (l = 1; l <= n; l++) {
          if (temp[l] != s[l]) {
            ch = 1;
            break;
          }
        }
        if (!ch) f1 = 1;
      }
      if (f2 == 0 && f1 == 0) {
        fa = 1;
      }
    } else if (cq > cqi) {
      cq = cq - cqi;
      for (j = 1; j <= cq; j++) {
        for (l = 1; l <= n; l++) local[l] = temp[q[l]];
        for (l = 1; l <= n; l++) temp[l] = local[l];
        if (j != cq) {
          ch = 0;
          for (l = 1; l <= n; l++) {
            if (temp[l] != s[l]) {
              ch = 1;
              break;
            }
          }
          if (!ch) f1 = 1;
        }
      }
      for (j = 1; j <= n; j++) {
        if (temp[j] != s[j]) {
          f2 = 1;
          break;
        }
      }
      if (cq == 1 && f2 == 0 && i > 1) {
        ch = 0;
        for (j = 1; j <= n; j++) temp[j] = j;
        for (l = 1; l <= n; l++) local[q[l]] = temp[l];
        for (l = 1; l <= n; l++) temp[l] = local[l];
        for (l = 1; l <= n; l++) {
          if (temp[l] != s[l]) {
            ch = 1;
            break;
          }
        }
        if (!ch) f1 = 1;
      }
      if (f2 == 0 && f1 == 0) {
        fa = 1;
      }
    } else {
    }
    if (fa) break;
  }
  if (fa && c)
    cout << "YES" << endl;
  else
    cout << "NO" << endl;
  return 0;
}
