#include <bits/stdc++.h>
using namespace std;
const long long int N = 1005;
map<long long int, long long int> m1[N];
map<long long int, long long int> m2[N];
int main() {
  ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
  srand(time(NULL));
  long long int n, m;
  cin >> n >> m;
  long long int ip[n][m];
  for (long long int i = 0; i < n; i++) {
    for (long long int j = 0; j < m; j++) {
      long long int x;
      cin >> x;
      ip[i][j] = x;
      m1[i + j][x]++;
    }
  }
  for (long long int i = 0; i < n; i++) {
    for (long long int j = 0; j < m; j++) {
      long long int x;
      cin >> x;
      m2[i + j][x]++;
    }
  }
  for (long long int i = 0; i < n; i++) {
    for (long long int j = 0; j < m; j++) {
      if (m1[i + j][ip[i][j]] != m2[i + j][ip[i][j]]) {
        cout << "NO";
        return 0;
      }
    }
  }
  cout << "YES";
}
