#include <bits/stdc++.h>
using namespace std;
int A[21][21];
int n, m;
void S(int a, int b) {
  for (int i = 1; i <= n; ++i) swap(A[i][a], A[i][b]);
}
bool C() {
  for (int a = 1; a <= n; ++a) {
    int cnt = 0;
    for (int b = 1; b <= m; ++b)
      if (A[a][b] != b) ++cnt;
    if (cnt > 2) return 0;
  }
  return 1;
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cin >> n >> m;
  for (int i = 1; i <= n; ++i)
    for (int j = 1; j <= m; ++j) cin >> A[i][j];
  if (C()) {
    cout << "YES\n";
    return 0;
  }
  for (int i = 1; i <= m; ++i)
    for (int j = i + 1; j <= m; ++j) {
      S(i, j);
      if (C()) {
        cout << "YES\n";
        return 0;
      }
      S(i, j);
    }
  cout << "NO\n";
  return 0;
}
