#include <bits/stdc++.h>
using namespace std;
const long long MAXN = 500;
long long a[MAXN][MAXN];
long long b[MAXN][MAXN];
vector<long long> aa[MAXN * 2];
vector<long long> bb[MAXN * 2];
signed main() {
  ios_base::sync_with_stdio(false);
  long long n, m;
  cin >> n >> m;
  for (long long i = 0; i < n; ++i)
    for (long long j = 0; j < m; ++j) {
      cin >> a[i][j];
      aa[i + j].push_back(a[i][j]);
    }
  for (long long i = 0; i < n; ++i)
    for (long long j = 0; j < m; ++j) {
      cin >> b[i][j];
      bb[i + j].push_back(b[i][j]);
    }
  bool ok = 1;
  for (long long i = 0; i < MAXN * 2; ++i) {
    sort(aa[i].begin(), aa[i].end());
    sort(bb[i].begin(), bb[i].end());
    if (aa[i] != bb[i]) ok = 0;
  }
  if (ok)
    cout << "YES";
  else
    cout << "NO";
  return 0;
}
