#include <bits/stdc++.h>
using namespace std;
int n, m, a[505][505], b[505][505];
multiset<int> sa[1005], sb[1005];
int main() {
  int i, j;
  cin >> n >> m;
  for (i = 1; i <= n; i++)
    for (j = 1; j <= m; j++) {
      cin >> a[i][j];
      sa[i + j].insert(a[i][j]);
    }
  for (i = 1; i <= n; i++)
    for (j = 1; j <= m; j++) {
      cin >> b[i][j];
      sb[i + j].insert(b[i][j]);
    }
  for (i = 2; i <= n + m; i++)
    if (sa[i] != sb[i]) {
      cout << "NO";
      return 0;
    }
  cout << "YES";
  return 0;
}
