#include <bits/stdc++.h>
using namespace std;
const int N = 20 + 3;
int a[N][N], tmp[N][N];
int n, m;
bool pd(int a[N][N]) {
  for (int i = 1; i <= n; i++) {
    int cnt = 0;
    for (int j = 1; j <= m; j++)
      if (a[i][j] != j) cnt++;
    if (cnt > 2) return 0;
  }
  return 1;
}
void init() {
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= m; j++) tmp[i][j] = a[i][j];
}
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= m; j++) scanf("%d", &a[i][j]);
  if (pd(a)) {
    printf("YES");
    return 0;
  }
  bool flag = 0;
  for (int i = 1; i <= m - 1; i++) {
    for (int j = i + 1; j <= m; j++) {
      init();
      for (int k = 1; k <= n; k++) swap(tmp[k][i], tmp[k][j]);
      if (pd(tmp)) {
        flag = 1;
        break;
      }
    }
    if (flag) break;
  }
  if (flag)
    printf("YES");
  else
    printf("NO");
  return 0;
}
