#include <bits/stdc++.h>
using namespace std;
int gcd(int a, int b) {
  if (b == 0)
    return a;
  else
    return gcd(b, a % b);
}
int n, m;
int a[1010][1010], b[1010][1010];
int main() {
  scanf("%d %d", &n, &m);
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= m; j++) scanf("%d", &a[i][j]);
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= m; j++) scanf("%d", &b[i][j]);
  for (int i = 1; i <= m; i++) {
    int x = 1, y = i;
    vector<int> vecA;
    vector<int> vecB;
    while (x <= n && y >= 1) {
      vecA.push_back(a[x][y]);
      vecB.push_back(b[x][y]);
      x++;
      y--;
    }
    sort(vecA.begin(), vecA.end());
    sort(vecB.begin(), vecB.end());
    for (int i = 0; i < ((int)(vecA.size())); i++)
      if (vecA[i] != vecB[i]) {
        puts("NO");
        return 0;
      }
  }
  for (int i = 1; i <= n; i++) {
    int x = i, y = m;
    vector<int> vecA;
    vector<int> vecB;
    while (x <= n && y >= 1) {
      vecA.push_back(a[x][y]);
      vecB.push_back(b[x][y]);
      x++;
      y--;
    }
    sort(vecA.begin(), vecA.end());
    sort(vecB.begin(), vecB.end());
    for (int i = 0; i < ((int)(vecA.size())); i++)
      if (vecA[i] != vecB[i]) {
        puts("NO");
        return 0;
      }
  }
  puts("YES");
  return 0;
}
