#include <bits/stdc++.h>
using namespace std;
using namespace std;
const int MAXN = 1 + 1e3;
int n, a[MAXN][MAXN], b[MAXN][MAXN], k, m;
vector<int> ga[MAXN], gb[MAXN];
void solve() {
  cin >> n >> m;
  for (int i = 1; i <= n; ++i)
    for (int j = 1; j <= m; ++j) {
      cin >> a[i][j];
      ga[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];
      gb[i + j].push_back(b[i][j]);
    }
  for (int i = 2; i <= m + n; ++i) {
    sort(ga[i].begin(), ga[i].end());
    sort(gb[i].begin(), gb[i].end());
  }
  for (int i = 2; i <= n + m; ++i) {
    for (int j = 0; j < ga[i].size(); ++j) {
      if (ga[i][j] != gb[i][j]) {
        cout << "NO";
        return;
      }
    }
  }
  cout << "YES";
}
int main() {
  ios_base::sync_with_stdio(0);
  solve();
  return 0;
}
