#include <bits/stdc++.h>
using namespace std;
int n, m, matrixA[505][505], matrixB[505][505];
bool fetch(int ith, int jth) {
  for (int i = ith, j = jth; i >= 0 && j < m; i--, j++) {
    if (matrixA[i][j] == matrixB[ith][jth]) {
      matrixA[i][j] = 0;
      return true;
    }
  }
  for (int i = ith + 1, j = jth - 1; i < n && j >= 0; i++, j--) {
    if (matrixA[i][j] == matrixB[ith][jth]) {
      matrixA[i][j] = 0;
      return true;
    }
  }
  return false;
}
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      scanf("%d", &matrixA[i][j]);
    }
  }
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      scanf("%d", &matrixB[i][j]);
    }
  }
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      if (false == fetch(i, j)) {
        printf("NO\n");
        return 0;
      }
    }
  }
  printf("YES\n");
  return 0;
}
