#include <bits/stdc++.h>
using namespace std;
const int MAX = 3 + 1e3;
const int INF = 0x3f3f3f3f;
int n, m;
int a[501][501], b[501][501];
vector<int> g[MAX], e[MAX];
int main() {
  int kt = 1;
  cin >> n >> m;
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= m; j++) {
      cin >> a[i][j];
      g[i + j].push_back(a[i][j]);
    }
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= m; j++) {
      cin >> b[i][j];
      e[i + j].push_back(b[i][j]);
    }
  for (int i = 2; i <= m + n; i++) {
    sort(g[i].begin(), g[i].end());
    sort(e[i].begin(), e[i].end());
    int len = g[i].size();
    for (int j = 0; j < len; j++)
      if (g[i][j] != e[i][j]) {
        kt = 0;
        break;
      }
  }
  if (kt == 1)
    cout << "YES";
  else
    cout << "NO";
}
