#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m, i, j;
  cin >> n >> m;
  vector<vector<int>> a(n, vector<int>(m));
  vector<vector<int>> b(n, vector<int>(m));
  for (i = 0; i < n; i++) {
    for (j = 0; j < m; j++) {
      cin >> a[i][j];
    }
  }
  for (i = 0; i < n; i++) {
    for (j = 0; j < m; j++) {
      cin >> b[i][j];
    }
  }
  for (i = 0; i < n; i++) {
    j = 0;
    vector<int> v1;
    vector<int> v2;
    int i1 = i;
    while (i1 >= 0 && j < m) {
      v1.push_back(a[i1][j]);
      v2.push_back(b[i1][j]);
      i1--, j++;
    }
    sort(v1.begin(), v1.end());
    sort(v2.begin(), v2.end());
    if (v1 != v2) {
      cout << "NO";
      return (0);
    }
  }
  for (int j = 1; j < m; j++) {
    i = n - 1;
    vector<int> v1;
    vector<int> v2;
    int j1 = j;
    while (i >= 0 && j1 < m) {
      v1.push_back(a[i][j1]);
      v2.push_back(b[i][j1]);
      i--, j1++;
    }
    sort(v1.begin(), v1.end());
    sort(v2.begin(), v2.end());
    if (v1 != v2) {
      cout << "NO";
      return (0);
    }
  }
  cout << "YES";
}
