#include <bits/stdc++.h>
using namespace std;
int a[510][510];
int d[1010][510];
int d2[1010][510];
int x, y, nr[1010], nr2[1010];
int n, m, i, j, ok;
int main() {
  scanf("%d%d", &n, &m);
  for (i = 1; i <= n; i++)
    for (j = 1; j <= m; j++) scanf("%d", &a[i][j]);
  for (i = 1; i <= n; i++) {
    x = i;
    y = 1;
    nr[i] = 0;
    while (x > 0 && y <= m) {
      d[i][++nr[i]] = a[x][y];
      x--;
      y++;
    }
    sort(d[i] + 1, d[i] + nr[i] + 1);
  }
  for (i = 2; i <= m; i++) {
    x = n;
    y = i;
    nr[i + n - 1] = 0;
    while (x > 0 && y <= m) {
      d[i + n - 1][++nr[i + n - 1]] = a[x][y];
      x--;
      y++;
    }
    sort(d[i + n - 1] + 1, d[i + n - 1] + nr[i + n - 1] + 1);
  }
  for (i = 1; i <= n; i++)
    for (j = 1; j <= m; j++) scanf("%d", &a[i][j]);
  for (i = 1; i <= n; i++) {
    x = i;
    y = 1;
    nr2[i] = 0;
    while (x > 0 && y <= m) {
      d2[i][++nr2[i]] = a[x][y];
      x--;
      y++;
    }
    sort(d2[i] + 1, d2[i] + nr2[i] + 1);
  }
  for (i = 2; i <= m; i++) {
    x = n;
    y = i;
    nr2[i + n - 1] = 0;
    while (x > 0 && y <= m) {
      d2[i + n - 1][++nr2[i + n - 1]] = a[x][y];
      x--;
      y++;
    }
    sort(d2[i + n - 1] + 1, d2[i + n - 1] + nr2[i + n - 1] + 1);
  }
  ok = 1;
  for (i = 1; i <= n + m - 1 && ok; i++) {
    for (j = 1; j <= nr[i] && ok; j++)
      if (d[i][j] != d2[i][j]) ok = 0;
  }
  if (ok)
    printf("YES");
  else
    printf("NO");
  return 0;
}
