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