#include <bits/stdc++.h>
using namespace std;
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  int n, m;
  cin >> n >> m;
  vector<vector<int>> a(n, vector<int>(m));
  auto b = a;
  multiset<int> kek1, kek2;
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < m; ++j) {
      cin >> a[i][j];
      kek1.insert(a[i][j]);
    }
  }
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < m; ++j) {
      cin >> b[i][j];
      kek2.insert(b[i][j]);
    }
  }
  vector<int> keki4;
  vector<int> loli4;
  for (int i = 0; i < n + m; i++) {
    keki4.clear();
    loli4.clear();
    for (int j = 0; j < n + m; j++) {
      int k = i - j;
      if (k < 0 || j > m - 1 || k > n - 1) continue;
      keki4.push_back(a[k][j]);
      loli4.push_back(b[k][j]);
    }
    sort((keki4).begin(), (keki4).end());
    sort((loli4).begin(), (loli4).end());
    if (keki4 != loli4) {
      cout << "NO";
      return 0;
    }
  }
  cout << "YES";
}
