#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e6 + 10;
const long long mod = 1e9 + 7;
int n, m;
int a[555][555], b[555][555];
vector<int> v[1010], w[1010];
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cin >> n >> m;
  for (int i = 1; i <= n; ++i) {
    for (int j = 1; j <= m; ++j) {
      cin >> a[i][j];
      v[i + j].push_back(a[i][j]);
    }
  }
  for (int i = 1; i <= n; ++i) {
    for (int j = 1; j <= m; ++j) {
      cin >> b[i][j];
      w[i + j].push_back(b[i][j]);
    }
  }
  for (int i = 1; i <= n + m; ++i) {
    sort(v[i].begin(), v[i].end());
    sort(w[i].begin(), w[i].end());
    for (int j = 0; j < v[i].size(); ++j) {
      if (v[i][j] != w[i][j]) {
        cout << "NO" << endl;
        return 0;
      }
    }
  }
  cout << "YES" << endl;
  return 0;
}
