#include <bits/stdc++.h>
using namespace std;
const int M = 1e9 + 7;
int mul(int a, int b) { return (long long int)a * b % M; }
int power(int a, int b) {
  if (b == 0) return 1;
  int temp = power(a, b / 2);
  if (b % 2 == 0)
    return mul(temp, temp);
  else
    return mul(a, mul(temp, temp));
}
int inv(int v) { return power(v, M - 2); }
int arr[505][505];
int arr2[505][505];
unordered_map<int, int> ma[1004];
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int n, m;
  cin >> n >> m;
  for (int i = 0; i < n; i++)
    for (int j = 0; j < m; j++) cin >> arr[i][j];
  for (int i = 0; i < n; i++)
    for (int j = 0; j < m; j++) cin >> arr2[i][j];
  for (int i = 0; i < n; i++)
    for (int j = 0; j < m; j++) ma[i + j][arr[i][j]]++;
  for (int i = 0; i < n; i++)
    for (int j = 0; j < m; j++) {
      ma[i + j][arr2[i][j]]--;
      if (ma[i + j][arr2[i][j]] == 0) ma[i + j].erase(arr2[i][j]);
    }
  for (int i = 0; i < n; i++)
    for (int j = 0; j < m; j++)
      if (ma[i + j].size() != 0) {
        cout << "NO" << endl;
        return 0;
      }
  cout << "YES" << endl;
}
