#include <bits/stdc++.h>
using namespace std;
const int INF = 2e6;
const long long LINF = 8e18;
const int MOD = 1e9 + 7;
const long double EPS = 1e-9;
vector<long long> A[1005][2];
long long mat[502][502][2];
void zigzag(int N, int M, int d) {
  for (int i = 0; i < N + M; i++) {
    int start_c = max(0, i - N);
    int num_c = min(min(N, i), M - start_c);
    for (int j = 0; j < num_c; j++)
      A[i][d].push_back(mat[min(N, i) - 1 - j][start_c + j][d]);
  }
}
bool equal(vector<long long>& a, vector<long long>& b) {
  int n = (int)a.size();
  for (int i = 0; i < n; i++)
    if (a[i] != b[i]) return false;
  return true;
}
void sol(int N, int M) {
  for (int i = 0; i < N + M; i++)
    for (int j = 0; j < 2; j++) sort(A[i][j].begin(), A[i][j].end());
  for (int i = 0; i < N + M; i++) {
    if (!equal(A[i][0], A[i][1])) {
      printf("NO");
      return;
    }
  }
  printf("YES");
}
int main() {
  int N, M;
  scanf("%d", &N);
  ;
  scanf("%d", &M);
  ;
  for (int it = 0; it < 2; it++)
    for (int i = 0; i < N; i++)
      for (int j = 0; j < M; j++) scanf("%lld", &mat[i][j][it]);
  zigzag(N, M, 0);
  zigzag(N, M, 1);
  sol(N, M);
  return 0;
}
