#include <bits/stdc++.h>
using namespace std;
const int maxn = 1010;
int N, M;
int a[maxn][maxn], b[maxn][maxn];
map<int, int> vis[maxn];
int main() {
  scanf("%d%d", &N, &M);
  for (int i = 1; i <= N; i++) {
    for (int j = 1; j <= M; j++) {
      scanf("%d", &a[i][j]);
      vis[i + j - 1][a[i][j]]++;
    }
  }
  bool flag = true;
  for (int i = 1; i <= N; i++) {
    for (int j = 1; j <= M; j++) {
      scanf("%d", &b[i][j]);
      if (vis[i + j - 1][b[i][j]] <= 0) flag = false;
      vis[i + j - 1][b[i][j]]--;
    }
  }
  if (flag)
    printf("YES\n");
  else
    printf("NO\n");
  return 0;
}
