#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  cin >> n >> m;
  vector<int> a[1001];
  vector<int> b[1001];
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      int p;
      cin >> p;
      a[i + j].push_back(p);
    }
  }
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      int p;
      cin >> p;
      b[i + j].push_back(p);
    }
  }
  bool flag = true;
  for (int i = 0; i < 1001; i++) {
    sort(a[i].begin(), a[i].end());
    sort(b[i].begin(), b[i].end());
    if (a[i] != b[i]) {
      flag = false;
      break;
    }
  }
  if (flag) {
    cout << "YES";
  } else {
    cout << "NO";
  }
  return 0;
}
