#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], B[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];
  }
  int S = 0;
  for (int i = 0; i < m; i++) {
    int a = 0, b = i;
    vector<int> C, D;
    while (a < n && b >= 0) {
      C.push_back(A[a][b]);
      D.push_back(B[a][b]);
      a++;
      b--;
    }
    sort(C.begin(), C.end());
    sort(D.begin(), D.end());
    for (int j = 0; j < C.size(); j++) {
      if (C[j] != D[j]) {
        S++;
        break;
      }
    }
    if (S > 0) break;
  }
  for (int i = 1; i < n; i++) {
    int a = i, b = m - 1;
    vector<int> C, D;
    while (a < n && b >= 0) {
      C.push_back(A[a][b]);
      D.push_back(B[a][b]);
      a++;
      b--;
    }
    sort(C.begin(), C.end());
    sort(D.begin(), D.end());
    for (int j = 0; j < C.size(); j++) {
      if (C[j] != D[j]) {
        S++;
        break;
      }
    }
    if (S > 0) break;
  }
  if (S == 0)
    cout << "YES";
  else
    cout << "NO";
}
