#include <bits/stdc++.h>
using namespace std;
const long long int mod = 1e9 + 7;
const int N = 1000005;
long long int arr1[505][505];
long long int arr2[505][505];
int n, m;
int min(int a, int b) { return (a < b) ? a : b; }
int min(int a, int b, int c) { return min(min(a, b), c); }
int max(int a, int b) { return (a > b) ? a : b; }
int main() {
  ios::sync_with_stdio(false);
  cin.tie(NULL);
  cin >> n >> m;
  for (int i = 0; i < n; i++)
    for (int j = 0; j < m; j++) cin >> arr1[i][j];
  for (int i = 0; i < n; i++)
    for (int j = 0; j < m; j++) cin >> arr2[i][j];
  vector<long long int> check1, check2;
  for (int line = 1; line <= (n + m - 1); line++) {
    int start_m = max(0, line - n);
    int count = min(line, (m - start_m), n);
    for (int j = 0; j < count; j++) {
      check1.push_back(arr1[min(n, line) - j - 1][start_m + j]);
      check2.push_back(arr2[min(n, line) - j - 1][start_m + j]);
    }
    sort(check1.begin(), check1.end());
    sort(check2.begin(), check2.end());
    if (check1 != check2) return cout << "NO", 0;
    check1.clear();
    check2.clear();
  }
  return cout << "YES", 0;
}
