#include <bits/stdc++.h>
using namespace std;
int n, m;
int a[510][510];
int b[510][510];
vector<int> s[2][1010];
int main() {
  cin >> n >> m;
  cin.tie(NULL);
  ios_base::sync_with_stdio();
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= m; j++) {
      cin >> a[i][j];
      s[0][i + j].push_back(a[i][j]);
    }
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= m; j++) {
      cin >> b[i][j];
      s[1][i + j].push_back(b[i][j]);
    }
  for (long long i = 1; i <= n + m; i++) {
    sort(s[1][i].begin(), s[1][i].end());
    sort(s[0][i].begin(), s[0][i].end());
    if (s[1][i] != s[0][i]) {
      cout << "NO";
      return 0;
    }
  }
  cout << "YES";
  return 0;
}
