#include <bits/stdc++.h>
using namespace std;
const int N = 100005;
const int M = 505;
const long long mod = 1000000007;
const int inf = (1 << 30);
const long long linf = (1LL << 61);
int a[M][M], b[M][M], v[M], u[M], n, m, i, j, l;
bool ok = true;
int main() {
  ios::sync_with_stdio(false);
  cin.tie();
  cin >> n >> m;
  for (int i = 1; i <= n; ++i)
    for (int j = 1; j <= m; ++j) cin >> a[i][j];
  for (int i = 1; i <= n; ++i)
    for (int j = 1; j <= m; ++j) cin >> b[i][j];
  for (int z = 1; z <= n; ++z) {
    i = z;
    j = 1;
    l = 0;
    while (i >= 1 && j <= m) {
      ++l;
      v[l] = a[i][j];
      u[l] = b[i][j];
      --i;
      ++j;
    }
    sort(v + 1, v + l + 1);
    sort(u + 1, u + l + 1);
    ++l;
    while (--l)
      if (v[l] != u[l]) ok = false;
  }
  for (int z = 2; z <= m; ++z) {
    i = n;
    j = z;
    l = 0;
    while (i >= 1 && j <= m) {
      ++l;
      v[l] = a[i][j];
      u[l] = b[i][j];
      --i;
      ++j;
    }
    sort(v + 1, v + l + 1);
    sort(u + 1, u + l + 1);
    ++l;
    while (--l)
      if (v[l] != u[l]) ok = false;
  }
  if (ok == true)
    cout << "YES";
  else
    cout << "NO";
  return 0;
}
