#include <bits/stdc++.h>
using namespace std;
int arr[30][30], temp[30][30], ans;
int n, m;
void reset() {
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++) {
      temp[i][j] = arr[i][j];
    }
  }
}
void swaP(int a, int b) {
  reset();
  for (int i = 1; i <= n; i++) swap(temp[i][a], temp[i][b]);
}
int process() {
  int ret = 0;
  for (int i = 1; i <= n; i++) {
    int salah = 0;
    for (int j = 1; j <= m; j++) {
      if (temp[i][j] != j) salah++;
    }
    if (salah > 2) return 99999;
  }
  return 0;
}
int main() {
  ans = 999999;
  scanf("%d %d", &n, &m);
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++) {
      scanf("%d", &arr[i][j]);
      temp[i][j] = arr[i][j];
    }
  }
  int hehe = process();
  if (hehe <= n + 1) {
    puts("YES");
    return 0;
  }
  for (int i = 1; i <= m; i++) {
    for (int j = i + 1; j <= m; j++) {
      swaP(i, j);
      int haha = process();
      if (haha + 1 <= n + 1) {
        puts("YES");
        return 0;
      }
    }
  }
  puts("NO");
}
