#include <bits/stdc++.h>
using namespace std;
template <typename T>
void out(T x) {
  cout << x << endl;
  exit(0);
}
const int maxn = 1e6 + 11;
int n;
int m;
vector<vector<int>> a;
vector<vector<int>> b;
map<int, multiset<int>> as;
map<int, multiset<int>> bs;
void helper(int x, int y) {
  int moves = min(n - x, y - 1);
  for (int i = moves; x + i <= n, y - i >= 1, i > 0; i--) {
    if ((a[x + i][y - i] == b[x][y]) && (a[x][y] == b[x + i][y - i])) {
      a[x][y] = b[x][y];
      a[x + i][y - i] = b[x + i][y - i];
      return;
    }
  }
  out("NO");
}
void printa() {
  cout << "\n";
  cout << "printing A.\n";
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++) {
      cout << a[i][j] << " ";
    }
    cout << "\n";
  }
}
void printb() {
  cout << "\n";
  cout << "printing B.\n";
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++) {
      cout << b[i][j] << " ";
    }
    cout << "\n";
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cin >> n >> m;
  a.assign(n + 1, vector<int>(m + 1, 0));
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++) {
      cin >> a[i][j];
    }
  }
  b.assign(n + 1, vector<int>(m + 1, 0));
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++) {
      cin >> b[i][j];
    }
  }
  set<int> diags;
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++) {
      int diag = i + j;
      diags.insert(diag);
      as[diag].insert(a[i][j]);
      bs[diag].insert(b[i][j]);
    }
  }
  for (int diag : diags) {
    if (as[diag] != bs[diag]) out("NO");
  }
  out("YES");
  return 0;
}
