#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int n, m;
  cin >> n >> m;
  int A[n][m];
  int B[n][m];
  for (int i = 0; i <= n - 1; i++)
    for (int j = 0; j <= m - 1; j++) cin >> A[i][j];
  for (int i = 0; i <= n - 1; i++)
    for (int j = 0; j <= m - 1; j++) cin >> B[i][j];
  vector<int> arrA[n + m];
  for (int i = 0; i <= n - 1; i++)
    for (int j = 0; j <= m - 1; j++) arrA[i + j].emplace_back(A[i][j]);
  vector<int> arrB[n + m];
  for (int i = 0; i <= n - 1; i++)
    for (int j = 0; j <= m - 1; j++) arrB[i + j].emplace_back(B[i][j]);
  for (int i = 0; i <= n + m - 2; i++) {
    sort(arrA[i].begin(), arrA[i].end());
    sort(arrB[i].begin(), arrB[i].end());
  }
  bool flag = true;
  for (int i = 0; i <= n + m - 2; i++) {
    int vecLen = arrA[i].size();
    for (int j = 0; j <= vecLen - 1; j++)
      if (arrA[i][j] != arrB[i][j]) {
        flag = false;
        break;
      }
  }
  if (flag)
    cout << "YES" << '\n';
  else
    cout << "NO" << '\n';
  return 0;
}
