#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1000000007LL;
int t[20 + 2][20 + 2];
int n, m;
bool check() {
  for (int i = 0, _n = n; i < _n; i++) {
    int stnrb = 0;
    for (int j = 0, _n = m; j < _n; j++)
      if (t[i][j] != j) stnrb++;
    if (stnrb != 0 && stnrb != 2) return 0;
  }
  return 1;
}
void clmnswp(int a, int b) {
  for (int i = 0, _n = n; i < _n; i++) swap(t[i][a], t[i][b]);
}
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 0, _n = n; i < _n; i++) {
    for (int j = 0, _n = m; j < _n; j++) {
      int tr;
      scanf("%d", &tr);
      t[i][j] = tr - 1;
    }
  }
  bool ok = 0;
  if (check()) ok = 1;
  for (int i = 0, _n = m; i < _n; i++) {
    for (int j = i + 1, _n = m; j < _n; j++) {
      clmnswp(i, j);
      ok = ok | check();
      clmnswp(i, j);
    }
  }
  if (ok)
    printf("YES\n");
  else
    printf("NO\n");
  return 0;
}
