#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 5;
const int MOD = 1e9 + 7;
const int INF = 1e9;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(NULL);
  cout.tie(NULL);
  int n, m;
  cin >> n >> m;
  int a[n][m], b[n][m];
  vector<int> col[n + m], col2[n + m];
  int i, j;
  bool ans = true;
  for (i = 0; i < n; i++) {
    for (j = 0; j < m; j++) {
      cin >> a[i][j];
    }
  }
  for (i = 0; i < n; i++) {
    for (j = 0; j < m; j++) {
      cin >> b[i][j];
    }
  }
  for (i = 0; i < n; i++) {
    for (j = 0; j < m; j++) {
      col[i + j].push_back(a[i][j]);
      col2[i + j].push_back(b[i][j]);
    }
  }
  for (i = 0; i < (n + m - 1); i++) {
    sort(col[i].begin(), col[i].end());
    sort(col2[i].begin(), col2[i].end());
    if (col[i] != col2[i]) {
      ans = false;
    }
  }
  if (ans) {
    cout << "YES";
  } else {
    cout << "NO";
  }
  return 0;
}
