#include <bits/stdc++.h>
using namespace std;
const char IO_MODE = 0;
inline long long ReadInt() {
  long long x = 0, f = 1;
  char ch = getchar();
  while (ch < '0' || ch > '9') {
    if (ch == '-') f = -1;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9') {
    x = x * 10 + ch - '0';
    ch = getchar();
  }
  return x * f;
}
inline void WriteInt(long long x) {
  char CH[20];
  int Num = 0;
  if (!x) {
    putchar('0');
    return;
  }
  while (x > 0) CH[++Num] = x % 10, x /= 10;
  while (Num) putchar(CH[Num--] + 48);
}
inline void out(int x) {
  if (IO_MODE & 1)
    WriteInt(x);
  else
    printf("%i", x);
}
template <typename... Args>
inline void out(int x, Args... args) {
  out(x);
  putc(' ', stdout);
  out(args...);
}
inline void in(int &x) {
  if (IO_MODE & 2)
    x = ReadInt();
  else
    scanf("%i", &x);
}
template <typename... Args>
inline void in(int &x, Args &...args) {
  in(x);
  in(args...);
}
inline void outll(long long x) {
  if (IO_MODE & 1)
    WriteInt(x);
  else
    printf("%lld", x);
}
template <typename... Args>
inline void outll(long long x, Args... args) {
  outll(x);
  putc(' ', stdout);
  outll(args...);
}
inline void inll(long long &x) {
  if (IO_MODE & 2)
    x = ReadInt();
  else
    scanf("%lld", &x);
}
template <typename... Args>
inline void inll(long long &x, Args &...args) {
  inll(x);
  inll(args...);
}
int aa, bb, cc, dd, ee, ff, gg, hh, ii, jj, kk, mm, nn, oo, pp, qq, rr, ss, tt,
    uu, vv, ww, xx, yy, zz;
int tc, ty;
int n, m;
int A[555][555], B[555][555];
bool check() {
  if (A[0][0] != B[0][0] || A[n - 1][m - 1] != B[n - 1][m - 1]) return false;
  multiset<int> st[25010];
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      st[i + j].insert(A[i][j]);
    }
  }
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      auto it = st[i + j].find(B[i][j]);
      if (it == st[i + j].end())
        return false;
      else
        st[i + j].erase(it);
    }
  }
  return true;
}
int main() {
  in(n, m);
  for (int i = 0; i < n; i++)
    for (int j = 0; j < m; j++) in(A[i][j]);
  for (int i = 0; i < n; i++)
    for (int j = 0; j < m; j++) in(B[i][j]);
  if (check())
    printf("YES");
  else
    printf("NO");
  putc('\n', stdout);
}
