#include <bits/stdc++.h>
using namespace std;
const int MaxN = 110;
int a[MaxN], q[MaxN], s[MaxN], n, m;
bool View[MaxN];
int Total, p[MaxN];
map<int, bool> Mark;
bool f[MaxN][MaxN * 2 + 1];
inline bool Check() {
  for (int i = 1; i <= n; ++i)
    if (s[i] != a[i]) return 0;
  return 1;
}
int main() {
  cin >> n >> m;
  for (int i = 1; i <= n; ++i) cin >> q[i];
  for (int i = 1; i <= n; ++i) cin >> s[i];
  for (int e = -m; e <= m; ++e) {
    memset(View, 0, sizeof(View));
    for (int i = 1, j, k; i <= n; ++i)
      if (!View[i]) {
        p[0] = i;
        Total = 1;
        View[i] = 1;
        for (j = q[i]; j != i; j = q[j]) View[p[Total++] = j] = 1;
        k = (e % Total + Total) % Total;
        for (j = 0; j < Total; ++j) a[p[j]] = p[(j + k) % Total];
      }
    Mark[e] = Check();
  }
  for (int i = 1; i <= n; ++i) a[i] = i;
  f[0][MaxN] = !Check();
  for (int i = 1; i <= m; ++i)
    for (int j = -m; j <= m; ++j)
      f[i][j + MaxN] = (f[i - 1][j - 1 + MaxN] || f[i - 1][j + 1 + MaxN]) &&
                       ((i < m) ^ Mark[j]);
  bool Ans = 0;
  for (int i = -m; i <= m; ++i) Ans |= f[m][i + MaxN];
  cout << (Ans ? "YES" : "NO") << endl;
  return 0;
}
