#include <bits/stdc++.h>
using namespace std;
inline int read() {
  char c = getchar();
  int p = 1, ret = 0;
  while ((c < '0') || (c > '9')) {
    if (c == '-') p = -1;
    c = getchar();
  }
  while ((c >= '0') && (c <= '9'))
    ret = (ret << 1) + (ret << 3) + c - '0', c = getchar();
  return ret * p;
}
int n, m;
int a[25][25];
int main() {
  n = read();
  m = read();
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= m; j++) a[i][j] = read();
  for (int i = 1; i <= m; i++)
    for (int j = 1; j <= m; j++) {
      bool ok = true;
      for (int k = 1; k <= n; k++) {
        swap(a[k][i], a[k][j]);
        int s = 0, last;
        for (int l = 1; l <= m; l++)
          if (a[k][l] != l) {
            if (s == 2) {
              ok = false;
              break;
            } else if (s == 1)
              if ((a[k][l] != last) || (a[k][last] != l)) {
                ok = false;
                break;
              } else
                s = 2;
            else
              s = 1, last = l;
          }
        swap(a[k][i], a[k][j]);
      }
      if (ok) {
        printf("YES");
        return 0;
      }
    }
  printf("NO");
}
