#include <bits/stdc++.h>
using namespace std;
template <class T, class U>
inline void smin(T &a, U b) {
  if (a > b) a = b;
}
template <class T, class U>
inline void smax(T &a, U b) {
  if (a < b) a = b;
}
template <class T>
inline void gn(T &x) {
  char c, sg = 0;
  while (c = getchar(), (c > '9' || c < '0') && c != '-' && c != -1)
    ;
  if (c == -1) return;
  if (c == '-') sg = 1, c = getchar();
  for (x = 0; c >= '0' && c <= '9';
       x = (x << 1) + (x << 3) + c - '0', c = getchar())
    ;
  if (sg) x = -x;
}
template <class T>
void print(T x) {
  if (x < 0) return putchar('-'), print(-x);
  if (x < 10) {
    putchar(x + '0');
    return;
  }
  print(x / 10);
  putchar(x % 10 + '0');
}
template <class U, class V>
inline void gn(U &u, V &v) {
  gn(u);
  gn(v);
}
template <class U, class V, class W>
inline void gn(U &u, V &v, W &w) {
  gn(u);
  gn(v, w);
}
template <class T>
void println(T x) {
  print(x);
  putchar('\n');
}
template <class T>
void printsp(T x) {
  print(x);
  putchar(' ');
}
template <class U, class V>
inline void print(U u, V v) {
  printsp(u);
  println(v);
}
template <class U, class V, class W>
inline void print(U u, V v, W w) {
  printsp(u);
  print(v, w);
}
int power(int a, int b, int m, int ans = 1) {
  for (; b; a = (long long)a * a % m, b >>= 1)
    if (b & 1) ans = (long long)ans * a % m;
  return ans;
}
int q[222], tar[222];
int p[222][222];
int main() {
  int n, k;
  gn(n, k);
  for (int i = 1; i <= n; i++) gn(q[i]);
  for (int i = 1; i <= n; i++) gn(tar[i]);
  int flag = 0;
  for (int i = 1; i <= n; i++) {
    if (i != tar[i]) {
      flag = 1;
      break;
    }
  }
  if (!flag) {
    puts("NO");
    return 0;
  }
  for (int i = 1; i <= n; i++) p[111][i] = i;
  int L = k + 1, R = k + 1;
  for (int i = 110; i > 0; i--) {
    flag = 0;
    for (int j = 1; j <= n; j++) p[i][j] = p[i + 1][q[j]];
    for (int j = 1; j <= n; j++) {
      if (p[i][j] != tar[j]) {
        flag = 1;
        break;
      }
    }
    if (!flag) {
      L = 111 - i;
      break;
    }
  }
  for (int i = 112; i < 222; i++) {
    flag = 0;
    for (int j = 1; j <= n; j++) p[i][q[j]] = p[i - 1][j];
    for (int j = 1; j <= n; j++)
      if (p[i][j] != tar[j]) {
        flag = 1;
        break;
      }
    if (!flag) {
      R = i - 111;
      break;
    }
  }
  smin(L, k + 1);
  smin(R, k + 1);
  if (L == k + 1 && R == k + 1)
    puts("NO");
  else if (L == k + 1) {
    if (R % 2 == k % 2)
      puts("YES");
    else
      puts("NO");
  } else if (R == k + 1) {
    if (L % 2 == k % 2)
      puts("YES");
    else
      puts("NO");
  } else {
    if (L == k || R == k)
      puts("YES");
    else if (L % 2 == k % 2 || R % 2 == k % 2) {
      if (L > 1 || R > 1)
        puts("YES");
      else
        puts("NO");
    } else
      puts("NO");
  }
  return 0;
}
