#include <bits/stdc++.h>
using namespace std;
using namespace std;
void io() {}
long long arr[1000001];
long long brr[1000001];
long long tree[1000001];
map<long long, long long> mp;
vector<long long> adj[1000001];
long long vis[1000001];
long long n, m, k, l, r, x, y, t, a, b, q;
long long ans, cnt, tmp, sum, ind, mn = 100000000000000000,
                                   mx = -100000000000000000;
signed main() {
  io();
  ios ::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cin >> n >> m;
  int mat[n][m];
  int bat[n][m];
  for (int i = 0; i < int(n); ++i)
    for (int j = 0; j < int(m); ++j) cin >> mat[i][j];
  for (int i = 0; i < int(n); ++i)
    for (int j = 0; j < int(m); ++j) cin >> bat[i][j];
  for (int j = 0; j < int(m); ++j) {
    vector<long long> va;
    vector<long long> vb;
    int k = 0;
    int l = j;
    while (k <= n - 1 && l >= 0) {
      va.push_back(mat[k][l]);
      k++;
      l--;
    }
    k = 0;
    l = j;
    while (k <= n - 1 && l >= 0) {
      vb.push_back(bat[k][l]);
      k++;
      l--;
    }
    sort(va.begin(), va.end());
    sort(vb.begin(), vb.end());
    for (int i = 0; i < int(va.size()); ++i) {
      if (va[i] != vb[i]) {
        cout << "NO" << '\n';
        return 0;
      }
    }
  }
  for (int i = 1; i <= int(n); ++i) {
    vector<long long> va;
    vector<long long> vb;
    int k = i;
    int l = m - 1;
    while (k <= n - 1 && l >= 0) {
      va.push_back(mat[k][l]);
      k++;
      l--;
    }
    k = i;
    l = m - 1;
    while (k <= n - 1 && l >= 0) {
      vb.push_back(bat[k][l]);
      k++;
      l--;
    }
    sort(va.begin(), va.end());
    sort(vb.begin(), vb.end());
    for (int i = 0; i < int(va.size()); ++i) {
      if (va[i] != vb[i]) {
        cout << "NO" << '\n';
        return 0;
      }
    }
  }
  cout << "YES" << '\n';
}
