import std.algorithm;
import std.array;
import std.conv;
import std.math;
import std.range;
import std.stdio;
import std.string;
import std.traits;

class InputReader {
  private:
  ubyte[] p;
  ubyte[] buffer;
  size_t cur;
  public:
  this () {
    buffer = uninitializedArray!(ubyte[])(16<<20);
    p = stdin.rawRead (buffer);
  }
  final ubyte skipByte (ubyte lo) {
    while (true) {
      auto a = p[cur .. $];
      auto r = a.find! (c => c >= lo);
      if (!r.empty) {
        cur += a.length - r.length;
        return p[cur++];
      }
      p = stdin.rawRead (buffer);
      cur = 0;
      if (p.empty) return 0;
    }
  }
  final ubyte nextByte () {
    if (cur < p.length) {
       return p[cur++];
    }
    p = stdin.rawRead (buffer);
    if (p.empty) return 0;
    cur = 1;
    return p[0];
  }
  template next(T) if (isUnsigned!T) {
    final T next () {
      T res = skipByte (48) - 48;
      while (true) {
        ubyte b = nextByte ();
        if (b < 48 || b >= 58) {
          break;
        }
        res = res * 10 + (b - 48);
      }
      return res;
    }
  }
}

void main() {
  auto r = new InputReader;
  immutable int n = r.next!uint;
  immutable int m = r.next!uint;
  auto a = uninitializedArray!(uint[][]) (n, m);
  auto b = uninitializedArray!(uint[][]) (n, m);
  foreach (i; 0 .. n) foreach (j; 0 .. m) a[i][j] = r.next!uint;
  foreach (i; 0 .. n) foreach (j; 0 .. m) b[i][j] = r.next!uint;
  bool test () {
    foreach (d; 0 .. n + m - 1) {
      uint[] X, Y;
      foreach (i; 0 .. n) {
        immutable j = d - i;
        if (j >= 0 && j < m) {
          X ~= a[i][j];
          Y ~= b[i][j];
        }
      }
      X.sort ();
      Y.sort ();
      debug stderr.writeln ("d = ", d);
      debug stderr.writeln ("X = ", X);
      debug stderr.writeln ("Y = ", Y);
      if (!equal (X, Y)) return false;
    }
    return true;
  }
  write (test () ? "YES" : "NO");
}

