#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  int m;
  scanf("%d", &n);
  scanf("%d", &m);
  int a[n][m];
  int b[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]);
    }
  }
  int row;
  int col;
  multiset<int> foo;
  multiset<int> bar;
  for (int i = 0; i < n; i++) {
    row = i;
    col = 0;
    while (row >= 0 && col < m) {
      foo.insert(a[row][col]);
      bar.insert(b[row][col]);
      row--;
      col++;
    }
    if (foo != bar) {
      cout << "NO" << '\n';
      return 0;
    }
    foo.clear();
    bar.clear();
  }
  for (int i = 0; i < m; i++) {
    row = n - 1;
    col = i;
    while (row >= 0 && col < m) {
      foo.insert(a[row][col]);
      bar.insert(b[row][col]);
      row--;
      col++;
    }
    if (foo != bar) {
      cout << "NO" << '\n';
      return 0;
    }
    foo.clear();
    bar.clear();
  }
  cout << "YES" << '\n';
  return 0;
}
