#include <bits/stdc++.h>
using namespace std;
int n, m;
void check(int (*M)[21]) {
  for (int i = (1); i <= (n); ++i) {
    int cnt = 0;
    for (int j = (1); j <= (m); ++j)
      if (M[i][j] != j) cnt++;
    if (cnt > 2) return;
  }
  puts("YES");
  exit(0);
}
int main() {
  int M[21][21];
  cin >> n >> m;
  for (int i = (1); i <= (n); ++i)
    for (int j = (1); j <= (m); ++j) cin >> M[i][j];
  for (int j = (1); j <= (m - 1); ++j)
    for (int k = (j + 1); k <= (m); ++k) {
      for (int i = (1); i <= (n); ++i) swap(M[i][j], M[i][k]);
      check(M);
      for (int i = (1); i <= (n); ++i) swap(M[i][j], M[i][k]);
    }
  check(M);
  puts("NO");
}
