#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:16777216")
using namespace std;
template <typename T>
inline bool remin(T& c, const T& n) {
  if (n < c) {
    c = n;
    return 1;
  }
  return 0;
}
template <typename T>
inline bool remin2(T& c, const T& n) {
  if (c < 0 || n < c) {
    c = n;
    return 1;
  }
  return 0;
}
template <typename T>
inline bool remax(T& c, const T& n) {
  if (c < n) {
    c = n;
    return 1;
  }
  return 0;
}
template <typename T>
inline void addmod(T& c, const T& n, const T& m) {
  c = (c + n) % m;
}
int _in;
int in() {
  scanf("%d", &_in);
  return _in;
}
const int N = 102, MOD = 1e9 + 7;
int tz, k;
vector<int> p, t;
int zip(const vector<int>& ptr) {
  long long z = 0;
  for (int i = 0; i < ptr.size(); ++i) {
    z = z * ptr.size() + ptr[i];
    z %= MOD;
  }
  return (int)z;
}
vector<int> perm(const vector<int>& a) {
  int i;
  vector<int> res(a.size());
  assert(a.size() == p.size());
  for ((i) = (0); (i) < ((a).size()); ++(i)) {
    res[p[i]] = a[i];
  }
  return res;
}
vector<int> invperm(const vector<int>& a) {
  int i;
  vector<int> res(a.size());
  assert(a.size() == p.size());
  for ((i) = (0); (i) < ((a).size()); ++(i)) {
    res[i] = a[p[i]];
  }
  return res;
}
map<int, set<int> > g;
void go(const vector<int>& a, const int& myz, const int& step) {
  int nextz;
  vector<int> next;
  set<int>& cg = g[myz];
  if (step <= k && myz != tz) {
    nextz = zip(next = perm(a));
    if (!cg.count(nextz)) {
      cg.insert(nextz);
      g[nextz].insert(myz);
      go(next, nextz, step + 1);
    }
    nextz = zip(next = invperm(a));
    if (!cg.count(nextz)) {
      cg.insert(nextz);
      g[nextz].insert(myz);
      go(next, nextz, step + 1);
    }
  }
}
map<int, set<int> > was;
bool sneak(const int& cz, const int& step) {
  if (cz == tz && step == k) {
    return true;
  } else if (step < k) {
    set<int>& cw = was[cz];
    if (!cw.count(step)) {
      cw.insert(step);
      set<int>& cg = g[cz];
      for (set<int>::iterator it = cg.begin(); it != cg.end(); ++it) {
        if (sneak(*it, step + 1)) {
          return true;
        }
      }
    }
  }
  return false;
}
int main() {
  int n, i, idz;
  scanf("%d%d", &n, &k);
  p.resize(n);
  for ((i) = (0); (i) < (n); ++(i)) {
    scanf("%d", &p[i]);
    p[i] -= 1;
  }
  t.resize(n);
  for ((i) = (0); (i) < (n); ++(i)) {
    scanf("%d", &t[i]);
    t[i] -= 1;
  }
  vector<int> id(n);
  for ((i) = (0); (i) < (n); ++(i)) {
    id[i] = i;
  }
  tz = zip(t);
  go(id, idz = zip(id), 0);
  g[tz].clear();
  puts(sneak(idz, 0) ? "YES" : "NO");
  return 0;
}
