#include <bits/stdc++.h>
using namespace std;
const long long int INF = 1e15;
const long long int MOD = 1e9 + 7;
template <typename T>
using vector2 = vector<vector<T>>;
template <typename T>
vector2<T> initVec2(size_t n0, size_t n1, T e = T()) {
  return vector2<T>(n0, vector<T>(n1, e));
}
template <typename T>
using vector3 = vector<vector<vector<T>>>;
template <typename T>
vector3<T> initVec3(size_t n0, size_t n1, size_t n2, T e = T()) {
  return vector3<T>(n0, vector2<T>(n1, vector<T>(n2, e)));
}
signed main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  long long int n, m;
  cin >> n >> m;
  auto a = initVec2<long long int>(n, m);
  auto b = initVec2<long long int>(n, m);
  for (long long int i = 0; i < (n); ++i)
    for (long long int j = 0; j < (m); ++j) cin >> a[i][j];
  for (long long int i = 0; i < (n); ++i)
    for (long long int j = 0; j < (m); ++j) cin >> b[i][j];
  vector<map<long long int, long long int>> sa(
      n + m, map<long long int, long long int>());
  vector<map<long long int, long long int>> sb(
      n + m, map<long long int, long long int>());
  for (long long int i = 0; i < (n); ++i) {
    for (long long int j = 0; j < (m); ++j) {
      sa[i + j][a[i][j]]++;
      sb[i + j][b[i][j]]++;
    }
  }
  for (long long int i = 0; i < (n + m); ++i) {
    for (pair<long long int, long long int> p : sa[i]) {
      if (sb[i][p.first] != p.second) {
        cout << "NO" << endl;
        return 0;
      }
    }
  }
  cout << "YES" << endl;
  return 0;
}
