#include <bits/stdc++.h>
using namespace std;
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int n, m;
  cin >> n >> m;
  vector<multiset<int>> all1(n + m, multiset<int>());
  vector<multiset<int>> all2(n + m, multiset<int>());
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      int x;
      cin >> x;
      all1[i + j].insert(x);
    }
  }
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      int x;
      cin >> x;
      all2[i + j].insert(x);
    }
  }
  bool fl = true;
  for (int i = 0; i < n + m; i++) {
    if (all1[i] == (all2[i])) {
    } else {
      fl = false;
    }
  }
  if (fl) {
    cout << "YES";
  } else {
    cout << "NO";
  }
  return 0;
}
