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