#include <bits/stdc++.h>
using namespace std;
const int dy[] = {-1, 0, 1, 0}, dx[] = {0, 1, 0, -1};
const double EPS = 1e-8;
const double PI = acos(-1.0);
int popcount(int n) { return __builtin_popcount(n); }
int popcount(long long n) { return __builtin_popcountll(n); }
template <class T>
int SIZE(T a) {
  return a.size();
}
template <class T>
string IntToString(T num) {
  string res;
  stringstream ss;
  ss << num;
  return ss.str();
}
template <class T>
T StringToInt(string str) {
  T res = 0;
  for (int i = 0; i < SIZE(str); i++) res = (res * 10 + str[i] - '0');
  return res;
}
template <class T>
T gcd(T a, T b) {
  if (b == 0) return a;
  return gcd(b, a % b);
}
template <class T>
T lcm(T a, T b) {
  return a / gcd(a, b) * b;
}
template <class T>
void PrintSeq(T &a, int sz) {
  for (int i = 0; i < sz; i++) {
    cout << a[i];
    if (sz == i + 1)
      cout << endl;
    else
      cout << ' ';
  }
}
bool EQ(double a, double b) { return abs(a - b) < EPS; }
bool EQV(complex<double> a, complex<double> b) {
  return EQ(a.real(), b.real()) & EQ(a.imag(), b.imag());
}
void fastStream() {
  cin.tie(0);
  std::ios_base::sync_with_stdio(0);
}
vector<string> split(string str, char del) {
  vector<string> res;
  for (int i = 0, s = 0; i < SIZE(str); i++) {
    if (str[i] == del) {
      if (i - s != 0) res.push_back(str.substr(s, i - s));
      s = i + 1;
    } else if (i == SIZE(str) - 1) {
      res.push_back(str.substr(s));
    }
  }
  return res;
}
int N, K;
int QS[101];
int SS[101];
int used[101];
int dfs(int now, int group) {
  used[now] = group;
  int res = 1;
  if (used[QS[now]] == -1) res += dfs(QS[now], group);
  return res;
}
long long extgcd(long long a, long long b, long long &x, long long &y) {
  long long d = a;
  if (b != 0) {
    d = extgcd(b, a % b, y, x);
    y -= (a / b) * x;
  } else {
    x = 1;
    y = 0;
  }
  return d;
}
long long mod_inverse(long long a, long long m) {
  long long x, y;
  extgcd(a, m, x, y);
  return (m + x % m) % m;
}
pair<int, int> linear_congruence(const vector<int> &A, const vector<int> &B,
                                 const vector<int> &M) {
  long long x = 0, m = 1;
  for (int i = 0; i < (int)A.size(); i++) {
    long long a = A[i] * m, b = B[i] - A[i] * x, d = gcd((long long)M[i], a);
    if (b % d != 0) return make_pair(0, -1);
    long long t =
        b / d * mod_inverse(a / d, (long long)M[i] / d) % ((long long)M[i] / d);
    x = x + m * t;
    m *= M[i] / d;
  }
  return make_pair(x % m, m);
}
pair<int, int> search(int group) {
  vector<int> v;
  for (int i = 0; i < N; i++)
    if (group == used[i]) v.push_back(i);
  int tmp[101];
  int ntmp[101];
  for (int i = 0; i < N; i++) tmp[i] = i;
  bool isMatch = true;
  for (int i = 0; i < (int)v.size(); i++)
    if (v[i] != SS[v[i]]) isMatch = false;
  if (isMatch) return make_pair(0, v.size());
  int cnt = 0;
  while (++cnt) {
    for (int i = 0; i < (int)v.size(); i++) ntmp[v[i]] = tmp[QS[v[i]]];
    for (int i = 0; i < (int)v.size(); i++) tmp[v[i]] = ntmp[v[i]];
    bool ok = true;
    for (int i = 0; i < (int)v.size(); i++)
      if (SS[v[i]] != tmp[v[i]]) ok = false;
    if (ok) return make_pair(cnt, v.size());
    ok = true;
    for (int i = 0; i < (int)v.size(); i++)
      if (v[i] != tmp[v[i]]) ok = false;
    if (ok) break;
  }
  return make_pair(-1, v.size());
}
int main() {
  memset(used, -1, sizeof(used));
  cin >> N >> K;
  for (int i = 0; i < N; i++) {
    cin >> QS[i];
    QS[i]--;
  }
  for (int i = 0; i < N; i++) {
    cin >> SS[i];
    SS[i]--;
  }
  bool isMatch = true;
  for (int i = 0; i < N; i++)
    if (i != SS[i]) isMatch = false;
  if (isMatch) {
    cout << "NO" << endl;
    return 0;
  }
  vector<int> v;
  int sz = 0;
  for (int i = 0; i < N; i++)
    if (used[i] == -1) v.push_back(dfs(i, sz++));
  long long all = 1;
  for (int i = 0; i < (int)v.size(); i++) all = lcm(all, (long long)v[i]);
  vector<int> A, B, M;
  bool ok = true;
  for (int i = 0; i < (int)v.size(); i++) {
    A.push_back(1);
    pair<int, int> p = search(i);
    B.push_back(p.first);
    M.push_back(p.second);
    if (B[i] == -1) {
      cout << "NO" << endl;
      return 0;
    }
  }
  vector<int> cand;
  if (ok) {
    pair<int, int> p = linear_congruence(A, B, M);
    if (p.second != -1) {
      while (p.first < 0) p.first += p.second;
      cand.push_back(p.first);
    }
  }
  for (int i = 0; i < (int)v.size(); i++) {
    B[i] = M[i] - B[i];
  }
  pair<int, int> p = linear_congruence(A, B, M);
  if (p.second != -1) {
    while (p.first < 0) p.first += p.second;
    cand.push_back(p.first);
  }
  for (int i = 0; i < (int)cand.size(); i++) {
    int c = cand[i];
    if ((K % 2 == 0 && c % 2 == 0 && c <= K) ||
        ((K % 2) && (c % 2) && c <= K)) {
      if (c != 1 || (K == 1 || !(cand[0] == 1 && cand[1] == 1))) {
        cout << "YES" << endl;
        return 0;
      }
    }
  }
  cout << "NO" << endl;
  return 0;
}
