#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int n, m;
  cin >> n >> m;
  vector<vector<int> > a(n, vector<int>(m)), b(n, vector<int>(m));
  vector<int> cA[1000], cB[1000];
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      cin >> a[i][j];
      cA[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];
      cB[i + j].push_back(b[i][j]);
    }
  }
  int c = 1;
  for (int i = 0; i < 1000; i++) {
    sort(cA[i].begin(), cA[i].end());
    sort(cB[i].begin(), cB[i].end());
    if (cA[i] != cB[i]) c = 0;
  }
  if (c)
    cout << "YES\n";
  else
    cout << "NO\n";
  return 0;
}
