#include <bits/stdc++.h>
using namespace std;
int n, m, a[501][501], b[501][501], val;
vector<int> adj1[10000], adj2[10000];
int main() {
  cin >> n >> m;
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= m; j++) cin >> val, adj1[i + j].push_back(val);
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= m; j++) cin >> val, adj2[i + j].push_back(val);
  for (int i = 1; i < 1000; i++) {
    sort(adj1[i].begin(), adj1[i].end());
    sort(adj2[i].begin(), adj2[i].end());
  }
  for (int i = 1; i < 1000; i++) {
    for (int j = 0; j < adj1[i].size(); j++) {
      if (adj1[i][j] != adj2[i][j]) {
        cout << "NO";
        return 0;
      }
    }
  }
  cout << "YES";
}
