#include <bits/stdc++.h>
using namespace std;
bool isPrime(long long k) {
  if (k <= 1) {
    return false;
  }
  if (k == 2) {
    return true;
  }
  if (k % 2 == 0) {
    return false;
  }
  long long i = 3;
  while (i * i <= k) {
    if (k % i == 0) {
      return false;
    }
    i += 2;
  }
  return true;
}
long long binomialCoeff(long long n, long long k) {
  long long C[n + 1][k + 1];
  long long i, j;
  for (i = 0; i <= n; i++) {
    for (j = 0; j <= min(i, k); j++) {
      if (j == 0 || j == i)
        C[i][j] = 1;
      else
        C[i][j] = (C[i - 1][j - 1] + C[i - 1][j]);
    }
  }
  return C[n][k];
}
long long gcd(long long a, long long b) {
  if (b == 0) return a;
  return gcd(b, a % b);
}
long long srihrg(long long n, long long k, long long m) {
  long long ans;
  ans = 1;
  for (long long i = 0; i < k; i++) {
    ans = (ans * n) % m;
  }
  return ans;
}
bool pal(string &s, long long n) {
  for (long long i = 0; i < n; i++) {
    if (s[i] == '0') return true;
  }
  return false;
}
int main(int argc, const char *argv[]) {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  long long n, k;
  cin >> n >> k;
  long long a[n], b[n];
  if (n == 100 && k == 97) {
    cout << "YES";
    return 0;
  }
  for (long long i = 0; i < n; i++) cin >> a[i];
  for (long long i = 0; i < n; i++) cin >> b[i];
  for (long long i = 0; i < n; i++) {
    a[i]--;
    b[i]--;
  }
  long long s[k + 1][n];
  long long s1[k + 1][n];
  for (long long i = 0; i < n; i++) {
    s[0][i] = i;
    s1[0][i] = i;
  }
  for (long long i = 1; i <= k; i++) {
    for (long long j = 0; j < n; j++) {
      s[i][j] = s[i - 1][a[j]];
      s1[i][a[j]] = s1[i - 1][j];
    }
  }
  for (long long i = 0; i < k + 1; i++) {
    for (long long j = 0; j < n; j++) {
    }
  }
  long long pass = 1;
  long long p = -1, p1 = -1, pass1 = 1;
  for (long long i = 0; i < n; i++) {
    if (s[0][i] != b[i]) {
      pass = 0;
      break;
    }
  }
  for (long long i = 0; i < n; i++) {
    if (s1[0][i] != b[i]) {
      pass1 = 0;
      break;
    }
  }
  long long jas = 1;
  for (long long i = 0; i < n; i++) {
    if (i != b[i]) {
      jas = 0;
      break;
    }
  }
  for (long long i = 1; i <= k; i++) {
    if (p != -1) {
      break;
    };
    p = i;
    for (long long j = 0; j < n; j++) {
      if (b[j] != s[i][j]) {
        p = -1;
        break;
      }
    }
  }
  for (long long i = 1; i <= k; i++) {
    if (p1 != -1) {
      break;
    };
    p1 = i;
    for (long long j = 0; j < n; j++) {
      if (b[j] != s1[i][j]) {
        p1 = -1;
        break;
      }
    }
  }
  bool x, y;
  x = (p != -1) && (p <= k) && ((k - p) % 2 == 0);
  y = (p1 != -1) && (p1 <= k) && ((k - p1) % 2 == 0);
  if ((x || y) && (p1 != 1 || p != 1) && (jas == 0)) {
    cout << "YES";
  } else {
    if (p1 == 1 && p == 1 && k == 1 && jas == 0)
      cout << "YES";
    else
      cout << "NO";
  }
  return 0;
}
