#include <bits/stdc++.h>
using namespace std;
int n, a[110], b[110], k;
int p[110];
int t[110];
bool ch() {
  for (int i = 1; i <= n; i++) {
    if (b[i] != p[i]) return 0;
  }
  return 1;
}
int main() {
  ios::sync_with_stdio(0);
  cin >> n;
  cin >> k;
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
  }
  for (int i = 1; i <= n; i++) {
    cin >> b[i];
  }
  for (int i = 1; i <= n; i++) p[i] = i;
  if (ch()) {
    cout << "NO";
    return 0;
  }
  bool b1 = 0;
  bool b2 = 0;
  for (int i = 1; i <= 100 * k; i++) {
    for (int j = 1; j <= n; j++) {
      t[j] = p[a[j]];
    }
    for (int j = 1; j <= n; j++) {
      p[j] = t[j];
    }
    if (ch()) {
      if (i != 1 && (k - i) % 2 == 0 || (k == i)) {
        if (k >= i) {
          cout << "YES";
          return 0;
        }
      } else if (i == 1 && (k - i) % 2 == 0) {
        b2 = 1;
        break;
      } else {
        break;
      }
    }
  }
  for (int i = 1; i <= n; i++) p[i] = i;
  for (int i = 1; i <= 100 * k; i++) {
    for (int j = 1; j <= n; j++) {
      t[a[j]] = p[j];
    }
    for (int j = 1; j <= n; j++) {
      p[j] = t[j];
    }
    if (ch()) {
      if (i != 1 && (k - i) % 2 == 0 || (k == i)) {
        if (k >= i) {
          cout << "YES";
          return 0;
        }
      } else if (i == 1 && (k - i) % 2 == 0) {
        b1 = 1;
        break;
      } else {
        break;
      }
    }
  }
  if (b1 && !b2) {
    cout << "YES";
    return 0;
  }
  if (!b1 && b2) {
    cout << "YES";
    return 0;
  }
  cout << "NO";
  return 0;
}
