#include <bits/stdc++.h>
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize("unroll-loops")
using namespace std;
template <class T>
inline T bigmod(T p, T e, T M) {
  long long ret = 1;
  for (; e > 0; e >>= 1) {
    if (e & 1) ret = (ret * p) % M;
    p = (p * p) % M;
  }
  return (T)ret;
}
template <class T>
inline T gcd(T a, T b) {
  if (b == 0) return a;
  return gcd(b, a % b);
}
template <class T>
inline T modinverse(T a, T M) {
  return bigmod(a, M - 2, M);
}
template <class T>
inline T lcm(T a, T b) {
  a = abs(a);
  b = abs(b);
  return (a / gcd(a, b)) * b;
}
template <class T, class X>
inline bool getbit(T a, X i) {
  T t = 1;
  return ((a & (t << i)) > 0);
}
template <class T, class X>
inline T setbit(T a, X i) {
  T t = 1;
  return (a | (t << i));
}
template <class T, class X>
inline T resetbit(T a, X i) {
  T t = 1;
  return (a & (~(t << i)));
}
inline long long getnum() {
  char c = getchar();
  long long num, sign = 1;
  for (; c < '0' || c > '9'; c = getchar())
    if (c == '-') sign = -1;
  for (num = 0; c >= '0' && c <= '9';) {
    c -= '0';
    num = num * 10 + c;
    c = getchar();
  }
  return num * sign;
}
inline long long power(long long a, long long b) {
  long long multiply = 1;
  for (int i = (0); i < (b); i++) {
    multiply *= a;
  }
  return multiply;
}
int n, k, q[102], s[102], p[102], temp[102];
bool reached(int *a, int *b) {
  for (int i = (0); i < (n); i++) {
    if (a[i] != b[i]) return false;
  }
  return true;
}
void move1(int *a, int *b) {
  for (int i = (0); i < (n); i++) temp[i] = a[b[i]];
  for (int i = (0); i < (n); i++) a[i] = temp[i];
}
void move2(int *a, int *b) {
  for (int i = (0); i < (n); i++) temp[b[i]] = a[i];
  for (int i = (0); i < (n); i++) a[i] = temp[i];
}
int main() {
  int test, cases = 1;
  cin >> n >> k;
  for (int i = (0); i < (n); i++) {
    cin >> q[i];
    q[i]--;
  }
  for (int i = (0); i < (n); i++) {
    cin >> s[i];
    s[i]--;
  }
  for (int i = (0); i < (n); i++) p[i] = i;
  int t1 = -1, t2 = -1;
  for (int i = (0); i < (k + 1); i++) {
    if (reached(p, s)) {
      t1 = i;
      break;
    }
    move1(p, q);
  }
  for (int i = (0); i < (n); i++) p[i] = i;
  for (int i = (0); i < (k + 1); i++) {
    if (reached(p, s)) {
      t2 = i;
      break;
    }
    move2(p, q);
  }
  if (t1 == -1 && t2 == -1)
    cout << "NO"
         << "\n";
  else if (t1 == 0)
    cout << "NO"
         << "\n";
  else if ((t1 != 1 || t2 != 1) && k % 2 == t1 % 2) {
    cout << "YES"
         << "\n";
  } else if ((t1 != 1 || t2 != 1) && k % 2 == t2 % 2) {
    cout << "YES"
         << "\n";
  } else if (t1 == k || t2 == k) {
    cout << "YES"
         << "\n";
  } else
    cout << "NO"
         << "\n";
  return 0;
}
