#include <bits/stdc++.h>
using namespace std;
int a[25][25];
int r, c, ch = 0, ok, diff;
void swap(int x, int y) {
  int t;
  for (int i = 1; i <= r; i++) {
    t = a[i][x];
    a[i][x] = a[i][y];
    a[i][y] = t;
  }
}
int main() {
  scanf("%d %d", &r, &c);
  for (int i = 1; i <= r; i++)
    for (int j = 1; j <= c; j++) scanf("%d", &a[i][j]);
  ok = 1;
  for (int i = 1; i <= r; i++) {
    diff = 0;
    for (int j = 1; j <= c; j++) {
      if (a[i][j] != j)
        if (++diff > 2) {
          ok = 0;
          break;
        }
    }
    if (!ok) break;
  }
  if (ok) {
    printf("YES");
    return 0;
  }
  for (int ii = 1; ii <= c; ii++)
    for (int jj = ii + 1; jj <= c; jj++) {
      swap(ii, jj);
      ok = 1;
      for (int i = 1; i <= r; i++) {
        diff = 0;
        for (int j = 1; j <= c; j++) {
          if (a[i][j] != j)
            if (++diff > 2) {
              ok = 0;
              break;
            }
        }
        if (!ok) break;
      }
      if (ok) {
        printf("YES");
        return 0;
      }
      swap(ii, jj);
    }
  printf("NO");
  return 0;
}
