#include <bits/stdc++.h>
using namespace std;
int bg[103], n, k, q[103], tmp[103], s[103], cnt, needop;
int main() {
  cin >> n >> k;
  for (int i = 0; i < n; i++) {
    cin >> q[i];
    q[i]--;
    bg[i] = i;
  }
  for (int i = 0; i < n; i++) {
    cin >> s[i];
    s[i]--;
  }
  bool fnd = 0;
  for (int i = 0; i <= 300; i++) {
    for (int j = 0; j < n; j++) tmp[q[j]] = bg[j];
    for (int j = 0; j < n; j++) bg[j] = tmp[j];
    bool ok = 0;
    for (int j = 0; j < n; j++)
      if (bg[j] != j) ok = 1;
    cnt++;
    if (!ok) break;
    for (int j = 0; j < n; j++)
      if (s[j] != bg[j]) ok = 0;
    if (ok) {
      fnd = 1;
      needop = cnt;
    }
  }
  if (cnt == 2 && needop == 1 && k > 1) {
    cout << "NO";
    return 0;
  }
  if (fnd)
    if (needop % 2 == k % 2 && needop <= k) {
      cout << "YES";
      return 0;
    }
  for (int i = 0; i < n; i++) bg[i] = i;
  cnt = 0;
  needop = 0;
  fnd = 0;
  for (int i = 0; i <= 300; i++) {
    for (int j = 0; j < n; j++) tmp[j] = bg[q[j]];
    for (int j = 0; j < n; j++) bg[j] = tmp[j];
    bool ok = 0;
    for (int j = 0; j < n; j++)
      if (bg[j] != j) ok = 1;
    cnt++;
    if (!ok) break;
    for (int j = 0; j < n; j++)
      if (s[j] != bg[j]) ok = 0;
    if (ok) {
      fnd = 1;
      needop = cnt;
    }
  }
  if (!fnd) {
    cout << "NO";
    return 0;
  }
  if (needop % 2 == k % 2 && needop <= k) {
    cout << "YES";
    return 0;
  }
  cout << "NO";
}
