#include <bits/stdc++.h>
using namespace std;
const int maxn = 550;
const int inf = 1e9 + 7;
int a[maxn][maxn];
int b[maxn][maxn];
int main() {
  ios_base::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];
    }
  }
  for (int d = 0; d < n + m - 1; d++) {
    vector<int> va;
    vector<int> vb;
    for (int i = 0; i < n; i++) {
      int j = d - i;
      if (j < 0 || j >= m) {
        continue;
      }
      va.push_back(a[i][j]);
      vb.push_back(b[i][j]);
    }
    sort(va.begin(), va.end());
    sort(vb.begin(), vb.end());
    bool same = true;
    for (int i = 0; i < va.size(); i++) {
      if (va[i] != vb[i]) {
        same = false;
      }
    }
    if (!same) {
      cout << "NO" << endl;
      return 0;
    }
  }
  cout << "YES" << endl;
  return 0;
}
