#include <bits/stdc++.h>
using namespace std;
vector<long long> ve[100005];
long long vis[100005] = {0}, z = 0, i;
void solve() {
  vector<long long> v;
  vector<pair<long long, long long> > vp;
  map<long long, long long> mp, mpp;
  map<long long, long long>::iterator itr;
  long long n = 0, m = 0, i = 0, j = 0, k = 0, c = 0, l = 0, r = 0, p = 0,
            q = 0, x = 0, y = 0, z = 0, flag = 0, sum = 0;
  long long a[505][505] = {0}, b[505][505] = {0}, ans[100005];
  string s, t;
  cin >> n >> m;
  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 (j = 0; j < m; j++) {
    z = j;
    i = 0;
    while (i < n and z >= 0) {
      mp[a[i][z]]++;
      mpp[b[i][z]]++;
      i++;
      z--;
    }
    for (itr = mp.begin(); itr != mp.end(); ++itr) {
      if (mpp[itr->first] != itr->second) {
        cout << "NO" << endl;
        return;
      }
    }
    mp.clear();
    mpp.clear();
  }
  for (i = 1; i < n; i++) {
    z = i;
    j = m;
    while (z < n and j >= 0) {
      mp[a[z][j]]++;
      mpp[b[z][j]]++;
      j--;
      z++;
    }
    for (itr = mp.begin(); itr != mp.end(); ++itr) {
      if (mpp[itr->first] != itr->second) {
        cout << "NO" << endl;
        return;
      }
    }
    mp.clear();
    mpp.clear();
  }
  cout << "YES" << endl;
}
bool imp = false;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  int t = 1;
  if (imp) cin >> t;
  while (t--) solve();
  return 0;
}
