#include <bits/stdc++.h>
using namespace std;
int s[50][50], n, m;
int check() {
  int i, j, cnt;
  for (i = 1; i <= n; i++) {
    cnt = 0;
    for (j = 1; j <= m; j++)
      if (s[i][j] != j) cnt++;
    if (cnt > 2) return 0;
  }
  return 1;
}
int main() {
  int i, j, k;
  scanf("%d%d", &n, &m);
  for (i = 1; i <= n; i++)
    for (j = 1; j <= m; j++) scanf("%d", &s[i][j]);
  if (check()) {
    printf("YES\n");
    return 0;
  }
  for (i = 1; i < m; i++)
    for (j = i + 1; j <= m; j++) {
      for (k = 1; k <= n; k++) swap(s[k][i], s[k][j]);
      if (check()) {
        printf("YES\n");
        return 0;
      }
      for (k = 1; k <= n; k++) swap(s[k][i], s[k][j]);
    }
  printf("NO\n");
  return 0;
}
