#include <bits/stdc++.h>
using namespace std;
long long n, m;
long long arr[100][100];
bool safe() {
  for (long long i = 1; i <= n; i++) {
    long long cnt = 0;
    for (long long j = 1; j <= m; j++) {
      cnt += (arr[i][j] != j);
    }
    if (cnt > 2) return false;
  }
  return true;
}
signed main() {
  cin >> n >> m;
  for (long long i = 1; i <= n; i++) {
    for (long long j = 1; j <= m; j++) {
      cin >> arr[i][j];
    }
  }
  long long flag = safe();
  for (long long i = 1; i <= m; i++) {
    for (long long j = i + 1; j <= m; j++) {
      for (long long k = 1; k <= n; k++) {
        swap(arr[k][i], arr[k][j]);
      }
      flag |= safe();
      for (long long k = 1; k <= n; k++) {
        swap(arr[k][i], arr[k][j]);
      }
    }
  }
  if (flag) {
    cout << "YES" << endl;
  } else {
    cout << "NO" << endl;
  }
}
