#include <bits/stdc++.h>
using namespace std;
long long A[500][500], B[500][500];
bool funct(int i, int j, int n, int m) {
  unordered_map<long long, long long> umpa, umpb;
  int a = i, b = j;
  if (i == 0 && j == 0 && A[i][j] == B[i][j]) return true;
  if (i == (n - 1) && j == (m - 1) && A[i][j] == B[i][j]) return true;
  while (i >= 0 && j < m) {
    if (A[i][j] != B[i][j]) {
      umpa[A[i][j]]++;
      umpb[B[i][j]]++;
    }
    i--;
    j++;
  }
  while (a < n - 1 && b > 0) {
    a++;
    b--;
    if (A[a][b] != B[a][b]) {
      ++umpa[A[a][b]];
      ++umpb[B[a][b]];
    }
  }
  for (auto itr = umpa.begin(); itr != umpa.end(); itr++) {
    if (umpb[itr->first] != itr->second) return false;
  }
  return true;
}
int main() {
  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 flag = true;
  for (int i = 0; i < n && flag; i++) {
    flag = funct(i, 0, n, m);
  }
  for (int j = 1; j < m && flag; j++) {
    flag = funct(n - 1, j, n, m);
  }
  if (flag)
    cout << "YES" << endl;
  else
    cout << "NO" << endl;
  return 0;
}
