#include <bits/stdc++.h>
const int maxx = 500 + 10;
using namespace std;
int n, m;
int a[maxx][maxx], b[maxx][maxx];
map<int, int> aa[2 * maxx];
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]);
      aa[i + j - 1][a[i][j]]++;
    }
  }
  int flag = 1;
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++) {
      scanf("%d", &b[i][j]);
      if (aa[i + j - 1][b[i][j]] <= 0) flag = 0;
      aa[i + j - 1][b[i][j]]--;
    }
  }
  if (flag)
    printf("YES\n");
  else
    printf("NO\n");
  return 0;
}
