#include <bits/stdc++.h>
using namespace std;
const int mod = 1e8 + 7;
const int Max_N = 5e2 + 5;
int main(int argc, char const *argv[]) {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  int n, m;
  cin >> n >> m;
  vector<int> cnt[n + m + 4];
  vector<int> ans[n + m + 4];
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++) {
      int x;
      cin >> x;
      cnt[i + j].push_back(x);
    }
  }
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++) {
      int x;
      cin >> x;
      ans[i + j].push_back(x);
    }
  }
  for (int i = 2; i <= n + m; i++) {
    sort(cnt[i].begin(), cnt[i].end());
    sort(ans[i].begin(), ans[i].end());
    if (cnt[i] != ans[i]) {
      cout << "NO" << endl;
      return 0;
    }
  }
  cout << "YES" << endl;
  return 0;
}
