#include <bits/stdc++.h>
using namespace std;
#pragma comment(linker, "/STACK:255000000")
bool firstout = 1;
template <class T>
T &minn(T &a, T b) {
  if (b < a) a = b;
  return a;
}
template <class T>
T &maxx(T &a, T b) {
  if (a < b) a = b;
  return a;
}
int &madd(int &a, int b) {
  a += b;
  if (a >= 1000000009) a -= 1000000009;
  return a;
}
int &msub(int &a, int b) {
  a -= b;
  if (a < 0) a += 1000000009;
  return a;
}
int &mmult(int &a, int b) { return a = (long long)a * b % 1000000009; }
int mdiv(long long a, long long b, long long m) {
  a = (a % m + m) % m;
  b = (b % m + m) % m;
  if (a % b == 0) return a / b;
  return (a + m * mdiv(-a, m, b)) / b;
}
int n, m, q;
int A[1012], B[1012], AA[1012];
int X[1012], XX[1012];
int calc(int *A) {
  int i, j;
  for (i = (0); i < (n); ++i) X[i] = i;
  for (j = (0); j < (m); ++j) {
    for (i = (0); i < (n); ++i) XX[i] = A[X[i]];
    for (i = (0); i < (n); ++i) X[i] = XX[i];
    for (i = (0); i < (n); ++i)
      if (X[i] != B[i]) break;
    if (i == n) return j + 1;
  }
  return -1;
}
int main() {
  int i, j, k;
  char c;
  int a, d;
  int ts;
  for (ts = 1; scanf("%"
                     "d",
                     &(n)) > 0;
       ++ts) {
    scanf(
        "%"
        "d",
        &(m));
    for (i = (0); i < (n); ++i)
      scanf(
          "%"
          "d",
          &(A[i])),
          --A[i];
    for (i = (0); i < (n); ++i)
      scanf(
          "%"
          "d",
          &(B[i])),
          --B[i];
    for (i = (0); i < (n); ++i) AA[A[i]] = i;
    for (i = (0); i < (n); ++i)
      if (B[i] != i) break;
    if (i == n)
      printf(
          "%"
          "s",
          ("NO"));
    else {
      bool b = 0;
      for (i = (0); i < (n); ++i)
        if (A[i] != B[i]) break;
      if (i != n) b = 1;
      for (i = (0); i < (n); ++i)
        if (AA[i] != B[i]) break;
      if (i != n) b = 1;
      int res = calc(A);
      if (res >= 0 && (res == m || ((m - res) & 1) == 0 && b))
        printf(
            "%"
            "s",
            ("YES"));
      else {
        res = calc(AA);
        if (res >= 0 && (res == m || ((m - res) & 1) == 0 && b))
          printf(
              "%"
              "s",
              ("YES"));
        else
          printf(
              "%"
              "s",
              ("NO"));
      }
    }
    printf("\n"), firstout = 1;
  }
  return 0;
}
