#include <bits/stdc++.h>
using namespace std;
const long long mxn = 1e5 + 5;
const long long mxm = 1e5 + 5;
const long long INF = 0x3f3f3f3f;
const long long mod = 1e9 + 7;
const double eps = 1e-7;
const double pii = 3.1415926535898;
long long gcd(long long x, long long y) {
  if (y == 0)
    return x;
  else
    return gcd(y, x % y);
}
long long qpow(long long a, long long b) {
  long long ans = 1;
  while (b) {
    if (b & 1) ans = ans * a % mod;
    b >>= 1;
    a = a * a % mod;
  }
  return ans;
}
long long lowbit(long long x) { return (x & (-x)); }
long long qmul(long long a, long long b) {
  long long ans = 0;
  while (b) {
    if (b & 1) ans = (ans + a) % mod;
    b >>= 1;
    a = (a + a) % mod;
  }
  return ans;
}
long long a[505][505], b[505][505];
vector<long long> cnta[2005], cntb[2005];
signed main(void) {
  long long n, m;
  scanf("%lld%lld", &n, &m);
  for (long long i = 1; i <= n; i++) {
    for (long long j = 1; j <= m; j++) {
      scanf("%lld", &a[i][j]);
      cnta[i + j].push_back(a[i][j]);
    }
  }
  for (long long i = 1; i <= n; i++) {
    for (long long j = 1; j <= m; j++) {
      scanf("%lld", &b[i][j]);
      cntb[i + j].push_back(b[i][j]);
    }
  }
  long long flg = 1;
  for (long long i = 1; i <= 1005; i++) {
    long long sza = cnta[i].size();
    long long szb = cntb[i].size();
    if (sza != szb) {
      flg = 0;
      break;
    }
    sort(cnta[i].begin(), cnta[i].end());
    sort(cntb[i].begin(), cntb[i].end());
    long long ok = 1;
    for (long long j = 0; j < sza; j++) {
      if (cnta[i][j] != cntb[i][j]) {
        ok = 0;
        break;
      }
    }
    if (ok == 0) {
      flg = 0;
      break;
    }
  }
  printf(flg ? "YES\n" : "NO\n");
  return 0;
}
