#include <bits/stdc++.h>
using namespace std;
long long max(long long a, long long b) { return (a > b) ? a : b; }
long long gcd(long long a, long long b) { return (a == 0) ? b : gcd(b % a, a); }
vector<long long> v1;
vector<long long> v2;
int main() {
  long long n, m, i, j, k;
  long long a[501][501], b[501][501];
  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];
  if (n == 1 && m == 1) {
    if (a[1][1] == b[1][1])
      cout << "yes";
    else
      cout << "no";
    return 0;
  }
  for (k = 2; k <= n; k++) {
    i = k;
    j = 1;
    while (i > 0 && j <= m) {
      v1.push_back(a[i][j]);
      v2.push_back(b[i][j]);
      i--, j++;
    }
    sort(v1.begin(), v1.end());
    sort(v2.begin(), v2.end());
    if (!(v1 == v2)) {
      cout << "NO";
      return 0;
    }
    v1.clear();
    v2.clear();
  }
  for (k = 2; k <= m; k++) {
    j = k;
    i = n;
    while (i > 0 && j <= m) {
      v1.push_back(a[i][j]);
      v2.push_back(b[i][j]);
      i--, j++;
    }
    sort(v1.begin(), v1.end());
    sort(v2.begin(), v2.end());
    if (!(v1 == v2)) {
      cout << "no";
      return 0;
    }
    v1.clear();
    v2.clear();
  }
  if (a[1][1] == b[1][1]) cout << "yes" << endl;
  return 0;
}
