#include <bits/stdc++.h>
using namespace std;
vector<int> method1(vector<int> &p, vector<int> &q) {
  vector<int> res = p;
  for (int i = 0; i < (int)p.size(); i++) res[i] = p[q[i]];
  return res;
}
vector<int> method2(vector<int> &p, vector<int> &q) {
  vector<int> res = p;
  for (int i = 0; i < (int)p.size(); ++i) res[q[i]] = p[i];
  return res;
}
int main() {
  int n, k, k1;
  bool b = 0;
  scanf("%d %d", &n, &k);
  vector<int> w(n), q(n), temp1(n), temp2(n);
  for (int i = 0; i < n; ++i) scanf("%d", &q[i]), q[i]--;
  for (int i = 0; i < n; ++i) scanf("%d", &w[i]), temp1[i] = temp2[i] = i + 1;
  k1 = k;
  while (k1 > 0 && temp1 != w) k1--, temp1 = method1(temp1, q);
  if (temp1 == w && k > k1) {
    if (k1 == 0) {
      puts("YES\n");
      return 0;
    }
    vector<int> second = method2(w, q);
    if (second != w) {
      second = method2(second, q);
      if (second != w) {
        if (k1 % 2 == 0) {
          puts("YES\n");
          return 0;
        }
      }
    }
  }
  k1 = k;
  while (k1 > 0 && temp2 != w) k1--, temp2 = method2(temp2, q);
  if (temp2 == w && k > k1) {
    if (k1 == 0) {
      puts("YES\n");
      return 0;
    }
    vector<int> second = method1(w, q);
    if (second != w) {
      second = method1(second, q);
      if (second != w) {
        if (k1 % 2 == 0) {
          puts("YES\n");
          return 0;
        }
      }
    }
  }
  puts("NO\n");
  return 0;
}
