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