#include <bits/stdc++.h>
int a[510][510], b[510][510];
std::vector<int> c[1010], d[1010];
int main() {
  int n, m;
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= m; j++)
      scanf("%d", &a[i][j]), c[i + j].push_back(a[i][j]);
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= m; j++)
      scanf("%d", &b[i][j]), d[i + j].push_back(b[i][j]);
  bool flag = true;
  for (int i = 1; i <= n + m; i++) {
    if (!flag) break;
    std::sort(c[i].begin(), c[i].end());
    std::sort(d[i].begin(), d[i].end());
    for (int j = 1; j <= c[i].size(); j++)
      if (c[i] != d[i]) {
        flag = false;
        break;
      }
  }
  printf("%s\n", flag ? "YES" : "NO");
  return 0;
}
