#include <bits/stdc++.h>
using namespace std;
int main() {
  cin.sync_with_stdio(false);
  cin.tie(nullptr);
  int n, m;
  cin >> n >> m;
  vector<vector<int>> A(n, vector<int>(m));
  vector<vector<int>> B(n, vector<int>(m));
  for (int i = 0; i < n; ++i)
    for (int j = 0; j < m; ++j) cin >> A[i][j];
  for (int i = 0; i < n; ++i)
    for (int j = 0; j < m; ++j) cin >> B[i][j];
  bool res = true;
  for (int d = 0; d <= n - 1 + m - 1; ++d) {
    vector<int> da, db;
    for (int i = 0; i < n; ++i) {
      int j = d - i;
      if (!(0 <= j && j < m)) continue;
      da.push_back(A[i][j]);
      db.push_back(B[i][j]);
    }
    sort(da.begin(), da.end());
    sort(db.begin(), db.end());
    res &= da == db;
  }
  cout << (res ? "YES" : "NO") << endl;
  return 0;
}
