#include <bits/stdc++.h>
using namespace std;
int a[505][505], b[505][505];
vector<int> v1, v2;
int main() {
  int n, m;
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= m; j++) scanf("%d", &a[i][j]);
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= m; j++) scanf("%d", &b[i][j]);
  bool ok = 1;
  for (int i = 2; i <= n + m; i++) {
    v1.clear(), v2.clear();
    for (int r = 1; r <= n; r++) {
      int c = i - r;
      if (r >= 1 && r <= n && c >= 1 && c <= m) {
        v1.push_back(a[r][c]);
        v2.push_back(b[r][c]);
      }
    }
    sort(v1.begin(), v1.end());
    sort(v2.begin(), v2.end());
    for (int j = 0; j < v1.size(); j++) {
      if (v1[j] == v2[j]) continue;
      ok = 0;
    }
  }
  if (ok)
    printf("YES\n");
  else
    printf("NO\n");
}
