#include <bits/stdc++.h>
using namespace std;
inline int read() {
  int x = 0, ch = getchar(), f = 1;
  while (!isdigit(ch)) {
    if (ch == '-') f = -1;
    ch = getchar();
  }
  while (isdigit(ch)) x = x * 10 + ch - '0', ch = getchar();
  return x * f;
}
int n, k, to[105], pp[105], dest[105], vis[105], idx;
int valid[105][105];
vector<int> cycle[105];
int main() {
  n = read(), k = read();
  for (int i = 1; i <= n; ++i) to[i] = read();
  for (int i = 1; i <= n; ++i) pp[i] = read(), dest[pp[i]] = i;
  int fl = 1;
  for (int i = 1; i <= n; ++i)
    if (dest[i] != i) {
      fl = 0;
    }
  if (fl) return printf("NO\n"), 0;
  fl = 1;
  for (int i = 1; i <= n; ++i)
    if (!vis[i]) {
      ++idx;
      for (int j = i; !vis[j]; j = to[j]) {
        vis[j] = idx;
        cycle[idx].push_back(j);
      }
      if (cycle[idx].size() > 2) fl = 0;
    }
  if (fl) {
    int same = 1;
    for (int i = 1; i <= n; ++i)
      if (to[i] != pp[i]) {
        same = 0;
        break;
      }
    if (same && k == 1)
      cout << "YES\n";
    else
      cout << "NO\n";
    return 0;
  }
  for (int i = 1; i <= n; ++i) {
    int t = vis[i], p1, p2;
    for (int j = 0; j < cycle[t].size(); ++j) {
      if (cycle[t][j] == i) p1 = j;
      if (cycle[t][j] == dest[i]) p2 = j;
    }
    int sz = cycle[t].size();
    for (int p = 0; p <= k; ++p) {
      int q = k - p;
      if (((p1 + p - q) % sz + sz) % sz == p2) {
        valid[p][q]++;
      }
    }
  }
  for (int p = 0; p <= k; ++p)
    if (valid[p][k - p] == n) {
      cout << "YES\n";
      return 0;
    }
  cout << "NO\n";
  return 0;
}
