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