#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e6 + 9;
const int mod = 1e9 + 7;
const double eps = 0.00000;
const int inf = 0x3f3f3f3f;
const long long INF = ~0ULL >> 1;
const double Pi = acos(-1.0);
const int N = 5e8 + 1;
inline long long read() {
  char ch = getchar();
  long long x = 0, f = 1;
  while (ch < '0' || ch > '9') {
    if (ch == '-') f = -1;
    ch = getchar();
  }
  while ('0' <= ch && ch <= '9') {
    x = x * 10 + ch - '0';
    ch = getchar();
  }
  return x * f;
}
void local() {}
vector<int> a[maxn], b[maxn];
int n, m;
int main() {
  local();
  n = read();
  m = read();
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= m; j++) a[i + j].push_back(read());
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= m; j++) b[i + j].push_back(read());
  int flag = 0;
  for (int i = 2; i <= n + m; i++) {
    sort(a[i].begin(), a[i].end());
    sort(b[i].begin(), b[i].end());
    if (a[i] != b[i]) flag = 1;
  }
  if (flag)
    puts("NO");
  else
    puts("YES");
}
