#include <bits/stdc++.h>
using namespace std;
int ay[510][510];
int by[510][510];
map<int, int> mp[1100];
int main() {
  int n, m;
  cin >> n >> m;
  bool flag = true;
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < m; ++j) {
      cin >> ay[i][j];
      ++mp[i + j][ay[i][j]];
    }
  }
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < m; ++j) {
      cin >> ay[i][j];
      --mp[i + j][ay[i][j]];
      if (mp[i + j][ay[i][j]] < 0) flag = false;
    }
  }
  if (flag)
    cout << "YES" << endl;
  else
    cout << "NO" << endl;
  return 0;
}
