#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  vector<int> a[1005];
  vector<int> b[1005];
  cin >> n >> m;
  for (int i = 0; i < n; i++)
    for (int j = 0; j < m; j++) {
      int c;
      cin >> c;
      a[i + j].push_back(c);
    }
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      int c;
      cin >> c;
      b[i + j].push_back(c);
    }
  }
  for (int i = 0; i < n + m; i++) {
    sort(a[i].begin(), a[i].end());
    sort(b[i].begin(), b[i].end());
    if (a[i] != b[i]) {
      puts("NO");
      return 0;
    }
  }
  puts("YES");
  return 0;
}
