#include <bits/stdc++.h>
const int maxn = 510;
int n, m, A[maxn][maxn], B[maxn][maxn];
std::map<int, int> mp;
int judge() {
  for (int i = 0; i < n + m; ++i) {
    mp.clear();
    for (int j = 0; j <= i; ++j) {
      if (j < n && i - j < m) ++mp[A[j][i - j]];
    }
    for (int j = 0; j <= i; ++j) {
      if (j < n && i - j < m && (--mp[B[j][i - j]]) < 0) return 1;
    }
  }
  return 0;
}
int main() {
  while (~scanf("%d%d", &n, &m)) {
    for (int i = 0; i < n; ++i)
      for (int j = 0; j < m; ++j) scanf("%d", &A[i][j]);
    for (int i = 0; i < n; ++i)
      for (int j = 0; j < m; ++j) scanf("%d", &B[i][j]);
    puts(judge() ? "NO" : "YES");
  }
  return 0;
}
