#include <bits/stdc++.h>
using namespace std;
const long long M = 1e9 + 7;
const long long oo = 1e13;
vector<int> a[1001], b[1001];
int main() {
  int n, m;
  cin >> n >> m;
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < m; ++j) {
      int b;
      cin >> b;
      a[i + j].push_back(b);
    }
  }
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < m; ++j) {
      int a;
      cin >> a;
      b[i + j].push_back(a);
    }
  }
  bool b1 = true;
  for (int i = 0; i < 1001; ++i) {
    sort(a[i].begin(), a[i].end());
    sort(b[i].begin(), b[i].end());
    if (a[i] != b[i]) {
      b1 = false;
      break;
    }
  }
  cout << (b1 ? "YES" : "NO") << endl;
}
