#include <bits/stdc++.h>
using namespace std;
const int N = 505;
int n, m;
int a[N][N], b[N][N];
vector<int> aa[N << 1], bb[N << 1];
int main() {
  cin >> n >> m;
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= m; j++) cin >> a[i][j];
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= m; j++) cin >> b[i][j];
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++) {
      aa[i + j].push_back(a[i][j]);
      bb[i + j].push_back(b[i][j]);
    }
  }
  for (int i = 2; i <= n + m; i++) {
    sort(aa[i].begin(), aa[i].end());
    sort(bb[i].begin(), bb[i].end());
    if (aa[i] != bb[i]) {
      return cout << "NO", 0;
    }
  }
  cout << "YES";
  return 0;
}
