#include <bits/stdc++.h>
using namespace std;
int n, m;
int a[200], b[200], p[400][200], c[400], dp[400][200];
int find(int x, int y) {
  if (dp[x][y] != -1) return dp[x][y];
  if (c[x] && y) return dp[x][y] = 0;
  if (c[x] && !y) return dp[x][y] = 1;
  if (!y) return dp[x][y] = 0;
  int ret = 0;
  ret = max(ret, find(x - 1, y - 1));
  ret = max(ret, find(x + 1, y - 1));
  return dp[x][y] = ret;
}
int main() {
  scanf("%d%d", &n, &m);
  for (int i = (0); i < (n); i++) scanf("%d", a + i);
  for (int i = (0); i < (n); i++) scanf("%d", b + i);
  for (int i = (0); i < (n); i++) a[i]--;
  for (int i = (0); i < (n); i++) b[i]--;
  for (int i = (0); i < (n); i++) p[200][i] = i;
  int ok = 1;
  for (int i = (0); i < (n); i++)
    if (b[i] != i) ok = 0;
  c[200] = ok;
  for (int i = (1); i <= (m); i++) {
    ok = 1;
    for (int j = (0); j < (n); j++) p[200 + i][j] = p[200 + i - 1][a[j]];
    for (int j = (0); j < (n); j++)
      if (b[j] != p[200 + i][j]) ok = 0;
    c[200 + i] = ok;
    ok = 1;
    for (int j = (0); j < (n); j++) p[200 - i][a[j]] = p[200 - i + 1][j];
    for (int j = (0); j < (n); j++)
      if (b[j] != p[200 - i][j]) ok = 0;
    c[200 - i] = ok;
  }
  memset(dp, -1, sizeof(dp));
  if (find(200, m))
    puts("YES");
  else
    puts("NO");
  return 0;
}
