#include <bits/stdc++.h>
using namespace std;
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  ;
  long long n, m;
  cin >> n >> m;
  long long a[n][m], b[n][m];
  vector<long long> x[n + m - 1], y[n + m - 1];
  for (long long i = 0; i < n; i++)
    for (long long j = 0; j < m; j++) {
      cin >> a[i][j];
      x[i + j].emplace_back(a[i][j]);
    }
  for (long long i = 0; i < n; i++)
    for (long long j = 0; j < m; j++) {
      cin >> b[i][j];
      y[i + j].emplace_back(b[i][j]);
    }
  long long ok = 1;
  for (long long i = 0; i < n + m - 1; i++) {
    sort((x[i]).begin(), (x[i]).end());
    sort((y[i]).begin(), (y[i]).end());
    if (x[i].size() != y[i].size()) {
      ok = 0;
      break;
    }
    for (long long j = 0; j < x[i].size(); j++) {
      if (x[i][j] != y[i][j]) {
        ok = 0;
        break;
      }
    }
    if (ok == 0) break;
  }
  ok == 0 ? cout << "NO" : cout << "YES";
  return 0;
}
