#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1e9 + 7;
const int N = 1e6 + 6;
bool dzn(char k) {
  if (k == 'a' || k == 'i' || k == 'o' || k == 'e' || k == 'u') return true;
  return false;
}
vector<int> v1[N], v2[N];
int a[5006][5006];
int main() {
  ios_base::sync_with_stdio(false);
  cout.tie(0);
  cin.tie(0);
  int n, m;
  cin >> n >> m;
  for (int i = 0; i < (n); ++i) {
    for (int j = 0; j < (m); ++j) {
      cin >> a[i][j];
      v1[i + j].push_back(a[i][j]);
    }
  }
  for (int i = 0; i < (n); ++i) {
    for (int j = 0; j < (m); ++j) {
      cin >> a[i][j];
      v2[i + j].push_back(a[i][j]);
    }
  }
  for (int i = 0; i < (n + m); ++i) {
    sort(v1[i].begin(), v1[i].end());
    sort(v2[i].begin(), v2[i].end());
    if (v1[i] != v2[i]) {
      cout << "NO" << endl;
      return 0;
    }
  }
  cout << "YES" << endl;
  return 0;
}
