#include <bits/stdc++.h>
using namespace std;
const int N = 10000 + 11;
vector<int> v1[N], v2[N];
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int n, m;
  cin >> n >> m;
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= m; j++) {
      int l;
      cin >> l;
      v1[i + j].push_back(l);
    }
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= m; j++) {
      int l;
      cin >> l;
      v2[i + j].push_back(l);
    }
  for (int i = 1; i <= n + m + 5; 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";
}
