#include <bits/stdc++.h>
int a[22][22], n, m;
bool check() {
  int i, j, tot;
  for (i = 1; i <= n; i++) {
    tot = 0;
    for (j = 1; j <= m; j++)
      if (a[i][j] != j) tot++;
    if (tot != 0 && tot != 2) return 0;
  }
  return 1;
}
void swp(int x, int y) {
  int i, tmp;
  for (i = 1; i <= n; i++) {
    tmp = a[i][x];
    a[i][x] = a[i][y];
    a[i][y] = tmp;
  }
}
int main() {
  int i, j, flag;
  while (scanf("%d%d", &n, &m) != EOF) {
    for (i = 1; i <= n; i++)
      for (j = 1; j <= m; j++) scanf("%d", &a[i][j]);
    if (check())
      printf("YES\n");
    else {
      flag = 0;
      for (i = 1; i <= m; i++)
        for (j = i + 1; j <= m; j++) {
          swp(i, j);
          if (check()) {
            flag = 1;
            break;
          }
          swp(i, j);
        }
      if (flag)
        printf("YES\n");
      else
        printf("NO\n");
    }
  }
  return 0;
}
