#include <bits/stdc++.h>
using namespace std;
int a[500][500], b[500][500];
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int n, m;
  cin >> n >> m;
  for (int i = 0; i < n; i++)
    for (int j = 0; j < m; j++) cin >> a[i][j];
  for (int i = 0; i < n; i++)
    for (int j = 0; j < m; j++) cin >> b[i][j];
  bool ans = 1;
  for (int ind = 0; ind < n && ans; ind++) {
    int i = ind, j = 0;
    multiset<int> A, B;
    while (i >= 0 && j < m) {
      A.insert(a[i][j]);
      B.insert(b[i][j]);
      i--;
      j++;
    }
    if (A != B) ans = 0;
  }
  for (int ind = 1; ind < m && ans; ind++) {
    int i = n - 1, j = ind;
    multiset<int> A, B;
    while (i >= 0 && j < m) {
      A.insert(a[i][j]);
      B.insert(b[i][j]);
      i--;
      j++;
    }
    if (A != B) ans = 0;
  }
  if (ans)
    cout << "YES";
  else
    cout << "NO";
  return 0;
}
