#include <bits/stdc++.h>
using namespace std;
static const int INF = 500000000;
template <class T>
void debug(T a, T b) {
  for (; a != b; ++a) cerr << *a << ' ';
  cerr << endl;
}
int n, k;
int q[105], rev[105], s[105];
int cur[105], tmp[105];
int match[205];
bool solve() {
  for (int i = 0; i < n; ++i) cur[i] = i;
  for (int hoge = 0; hoge < k; ++hoge) {
    for (int i = 0; i < n; ++i) tmp[q[i]] = cur[i];
    for (int i = 0; i < n; ++i) cur[i] = tmp[i];
  }
  for (int hoge = 0; hoge < k * 2 + 1; ++hoge) {
    match[hoge] = 1;
    for (int i = 0; i < n; ++i)
      if (cur[i] != s[i]) match[hoge] = 0;
    for (int i = 0; i < n; ++i) tmp[i] = cur[q[i]];
    for (int i = 0; i < n; ++i) cur[i] = tmp[i];
  }
  if (match[k]) return false;
  for (int i = 0; i < k * 2 + 1; ++i)
    if (i != k && match[i] && i % 2 == 0) {
      if (i == k + 1) {
        if (k == 1) return true;
        if (match[k - 1] == 0) return true;
        continue;
      }
      if (i == k - 1) {
        if (k == 1) return true;
        if (match[k + 1] == 0) return true;
        continue;
      }
      int fail = 0;
      if (i < k) {
        for (int j = i + 1; j < k + 1; ++j)
          if (match[j]) fail = 1;
      } else {
        for (int j = k; j < i; ++j)
          if (match[j]) fail = 1;
      }
      if (!fail) return true;
    }
  return false;
}
int main() {
  cin >> n >> k;
  for (int i = 0; i < n; ++i) {
    cin >> q[i], --q[i];
    rev[q[i]] = i;
  }
  for (int i = 0; i < n; ++i) cin >> s[i], --s[i];
  if (solve())
    puts("YES");
  else
    puts("NO");
  return 0;
}
