#include <bits/stdc++.h>
using namespace std;
int main() {
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);
  int n, m;
  cin >> n >> m;
  vector<vector<vector<int>>> vec(2, vector<vector<int>>(n + m - 1));
  for (int k = 0; k < 2; ++k) {
    for (int i = 0; i < n; ++i) {
      for (int j = 0, a; j < m; ++j) {
        cin >> a;
        vec[k][i + j].push_back(a);
      }
    }
  }
  for (int i = 0; i < n + m - 1; ++i) {
    sort(vec[0][i].begin(), vec[0][i].end());
    sort(vec[1][i].begin(), vec[1][i].end());
  }
  if (vec[0] == vec[1]) {
    cout << "YES\n";
  } else {
    cout << "NO\n";
  }
  return 0;
}
