#include <bits/stdc++.h>
using namespace std;
void file() {}
void fast() {
  std::ios_base::sync_with_stdio(0);
  cin.tie(NULL);
}
const int N = 500 + 20;
int a[N][N], b[N][N];
int n, m;
bool can1() {
  for (int i = 0; i < n; i++) {
    multiset<int> s1, s2;
    int r = i, c = 0;
    while (r >= 0 && c < m) {
      s1.insert(a[r][c]);
      s2.insert(b[r][c]);
      r--, c++;
    }
    if (s1 != s2) {
      cout << "NO"
           << "\n";
      exit(0);
    }
  }
}
bool can2() {
  for (int i = 0; i < m; i++) {
    multiset<int> s1, s2;
    int r = n - 1, c = i;
    while (r >= 0 && c < m) {
      s1.insert(a[r][c]);
      s2.insert(b[r][c]);
      r--, c++;
    }
    if (s1 != s2) {
      cout << "NO"
           << "\n";
      exit(0);
    }
  }
}
int main() {
  file();
  fast();
  cin >> n >> m;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      cin >> a[i][j];
    }
  }
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      cin >> b[i][j];
    }
  }
  can1();
  can2();
  cout << "YES"
       << "\n";
}
