#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  cin >> n >> m;
  int arr[500][500];
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) cin >> arr[i][j];
  }
  int a;
  int flag = 1;
  int temp;
  int x, y;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      cin >> a;
      temp = 0;
      x = i;
      y = j;
      while (x >= 0 && y <= m - 1) {
        if (arr[x][y] && arr[x][y] == a) {
          arr[x][y] = 0;
          temp = 1;
          break;
        }
        x--;
        y++;
      }
      x = i;
      y = j;
      if (temp == 0) {
        while (x <= n - 1 && y >= 0) {
          if (arr[x][y] && arr[x][y] == a) {
            arr[x][y] = 0;
            temp = 1;
            break;
          }
          x++;
          y--;
        }
      }
      if (temp == 0) {
        flag = 0;
      }
    }
  }
  if (flag)
    cout << "YES";
  else
    cout << "NO";
}
