#include <bits/stdc++.h>
using namespace std;
int matA[510][510], matB[510][510];
map<int, int> mapa[1010];
int main() {
  int n, m;
  scanf("%d%d", &n, &m);
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < m; ++j) {
      scanf("%d", &matA[i][j]);
      mapa[i + j][matA[i][j]]++;
    }
  }
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < m; ++j) {
      scanf("%d", &matB[i][j]);
      if (mapa[i + j][matB[i][j]] == 0) {
        puts("NO");
        return 0;
      }
      mapa[i + j][matB[i][j]]--;
    }
  }
  cout << (matA[0][0] == matB[0][0] && matA[n - 1][m - 1] == matB[n - 1][m - 1]
               ? "YES"
               : "NO")
       << endl;
  return 0;
}
