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