#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m, i, j, p;
  cin >> n >> m;
  vector<int> a[n + m], b[n + m];
  for (i = 0; i < n; i++) {
    for (j = 0; j < m; j++) {
      cin >> p;
      a[i + j].push_back(p);
    }
  }
  for (i = 0; i < n; i++) {
    for (j = 0; j < m; j++) {
      cin >> p;
      b[i + j].push_back(p);
    }
  }
  p = 0;
  for (i = 0; i < n + m - 1; i++) sort(a[i].begin(), a[i].end());
  for (j = 0; j < n + m - 1; j++) sort(b[j].begin(), b[j].end());
  for (i = 0; i < n + m - 1; i++) {
    for (j = 0; j < a[i].size(); j++) {
      if (a[i][j] != b[i][j]) p = 1;
    }
  }
  if (p)
    cout << "NO";
  else
    cout << "YES";
  return 0;
}
