#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m, i, j, k;
  cin >> n >> m;
  vector<int> v1[505 * 2];
  vector<int> v2[505 * 2];
  int a, b, l1, l2;
  for (i = 0; i < n; i++) {
    for (j = 0; j < m; j++) {
      cin >> a;
      v1[i + j].push_back(a);
    }
  }
  for (i = 0; i < n; i++) {
    for (j = 0; j < m; j++) {
      cin >> b;
      v2[i + j].push_back(b);
    }
  }
  for (i = 0; i < 500 * 2; i++) {
    sort(v1[i].begin(), v1[i].end());
    sort(v2[i].begin(), v2[i].end());
    if (v1[i] != v2[i]) {
      cout << "NO" << endl;
      return 0;
    }
  }
  cout << "YES" << endl;
  return 0;
}
