#include <bits/stdc++.h>
using namespace std;
int a[31][31], b[31][31];
int main() {
  int n, m;
  scanf("%d%d", &n, &m);
  int i, j, ii, jj;
  for (i = 1; i <= n; i++)
    for (j = 1; j <= m; j++) scanf("%d", &a[i][j]);
  for (i = 1; i <= m; i++) {
    for (j = i; j <= m; j++) {
      for (ii = 1; ii <= n; ii++)
        for (jj = 1; jj <= m; jj++) b[ii][jj] = a[ii][jj];
      for (ii = 1; ii <= n; ii++) {
        int t = b[ii][i];
        b[ii][i] = b[ii][j];
        b[ii][j] = t;
      }
      bool flag = true;
      for (ii = 1; ii <= n; ii++) {
        int ss = 0;
        for (jj = 1; jj <= m; jj++) {
          if (b[ii][jj] != jj) ss++;
        }
        if (ss > 2) {
          flag = false;
          break;
        }
      }
      if (flag) {
        printf("YES\n");
        return 0;
      }
    }
  }
  printf("NO\n");
  return 0;
}
