#include <bits/stdc++.h>
using namespace std;
const int maxn = 500;
const int mod = 1e9 + 7;
int n, m;
int a[maxn][maxn], b[maxn][maxn];
vector<int> aa[maxn * 2];
vector<int> bb[maxn * 2];
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 0; i < n; i++)
    for (int j = 0; j < m; j++) {
      scanf("%d", &a[i][j]);
      aa[i + j].push_back(a[i][j]);
    }
  for (int i = 0; i < n; i++)
    for (int j = 0; j < m; j++) {
      scanf("%d", &b[i][j]);
      bb[i + j].push_back(b[i][j]);
    }
  for (int i = 0; i < n + m; i++) {
    sort(aa[i].begin(), aa[i].end());
    sort(bb[i].begin(), bb[i].end());
    if (aa[i] != bb[i]) return 0 * printf("NO\n");
  }
  printf("YES\n");
  return 0;
}
