#include <bits/stdc++.h>
using namespace std;
int n, m, i, j, x;
vector<int> a[1009], b[1009];
int main() {
  cin >> n >> m;
  for (i = 0; i < n; i++)
    for (j = 0; j < m; j++) {
      cin >> x;
      a[i + j].push_back(x);
    }
  for (i = 0; i < n; i++)
    for (j = 0; j < m; j++) {
      cin >> x;
      b[i + j].push_back(x);
    }
  for (i = 0; i < n + m; i++) {
    sort(a[i].begin(), a[i].end());
    sort(b[i].begin(), b[i].end());
    for (j = 0; j < a[i].size(); j++)
      if (a[i][j] != b[i][j]) {
        cout << "NO";
        return 0;
      }
  }
  cout << "YES";
  return 0;
}
