#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m, q;
  scanf("%d%d", &n, &m);
  const int N = 1000;
  multiset<int> mas[N], mass[N];
  for (int i = 0; i < n; ++i) {
    for (int k = 0; k < m; ++k) {
      scanf("%d", &q);
      mas[i + k].insert(q);
    }
  }
  for (int i = 0; i < n; ++i) {
    for (int k = 0; k < m; ++k) {
      scanf("%d", &q);
      mass[i + k].insert(q);
    }
  }
  for (int i = 0; i < m + n - 1; ++i) {
    if (mas[i] != mass[i]) {
      cout << "NO";
      return 0;
    }
  }
  cout << "YES";
}
