#include <bits/stdc++.h>
using namespace std;
bool ok(long long mat[][20], long long n, long long m) {
  for (long long i = 0; i < n; ++i) {
    long long cnt = 0;
    for (long long j = 0; j < m; ++j) {
      if (mat[i][j] != j + 1) ++cnt;
      if (cnt > 2) return 0;
    }
  }
  return 1;
}
int32_t main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  long long n, m;
  cin >> n >> m;
  long long mat[20][20];
  for (long long i = 0; i < n; ++i) {
    for (long long j = 0; j < m; ++j) cin >> mat[i][j];
  }
  if (ok(mat, n, m)) cout << "YES", exit(0);
  for (long long i = 0; i < m; ++i) {
    for (long long j = 0; j < m; ++j) {
      for (long long k = 0; k < n; ++k) {
        swap(mat[k][i], mat[k][j]);
      }
      if (ok(mat, n, m)) cout << "YES", exit(0);
      for (long long k = 0; k < n; ++k) {
        swap(mat[k][i], mat[k][j]);
      }
    }
  }
  cout << "NO";
}
