#include <bits/stdc++.h>
using namespace std;
multiset<int> po[1003], al[1003];
int main() {
  int n, m, x;
  scanf("%d%d", &n, &m);
  for (int i = 0; i < n; i++)
    for (int j = 0; j < m; j++) scanf("%d", &x), po[i + j].insert(x);
  for (int i = 0; i < n; i++)
    for (int j = 0; j < m; j++) scanf("%d", &x), al[i + j].insert(x);
  bool flag = false;
  for (int i = 0; i < n + m; i++) flag |= (al[i] != po[i]);
  if (flag)
    cout << "NO" << endl;
  else
    cout << "YES" << endl;
  al->clear();
  po->clear();
  return 0;
}
