#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  cin >> n >> m;
  long long arr[n + 5][m + 5], brr[n + 5][m + 5];
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++) {
      cin >> arr[i][j];
    }
  }
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++) {
      cin >> brr[i][j];
    }
  }
  for (int i = 1; i <= n; i++) {
    multiset<long long> s1, s2;
    for (int j = 1; j <= min(i, m); j++) {
      s1.insert(arr[i - j + 1][j]);
      s2.insert(brr[i - j + 1][j]);
    }
    if (s1 != s2) {
      cout << "NO" << endl;
      return 0;
    }
  }
  for (int j = 2; j <= m; j++) {
    multiset<long long> s1, s2;
    for (int i = n; i >= max(1, n - (m - j)); i--) {
      s1.insert(arr[i][j + n - i]);
      s2.insert(brr[i][j + n - i]);
    }
    if (s1 != s2) {
      cout << "NO" << endl;
      return 0;
    }
  }
  cout << "YES" << endl;
  return 0;
}
