#include <bits/stdc++.h>
using namespace std;
int main() {
  long long int n, m, i, j, p, q, l;
  cin >> n >> m;
  long long int a[n + 1][m + 1];
  long long int b[n + 1][m + 1];
  for (i = 0; i < n; i++)
    for (j = 0; j < m; j++) cin >> a[i][j];
  for (i = 0; i < n; i++)
    for (j = 0; j < m; j++) cin >> b[i][j];
  int flag = 1;
  long long int tableb[n + 1][m + 1];
  for (i = 0; i < n; i++)
    for (j = 0; j < m; j++) tableb[i][j] = 1;
  for (p = 0; p < n; p++) {
    for (q = 0; q < m; q++) {
      flag = 0;
      l = p + q;
      for (i = max((long long int)0, l - m + 1); i <= min(l, n - 1); i++) {
        j = l - i;
        if (b[i][j] == a[p][q] && tableb[i][j] == 1) {
          tableb[i][j] = 0;
          flag = 1;
          break;
        }
      }
      if (flag == 0) break;
    }
    if (flag == 0) break;
  }
  if (flag == 0)
    cout << "NO";
  else
    cout << "YES";
}
