#include <bits/stdc++.h>
using namespace std;
int next() {
  int x;
  cin >> x;
  return x;
}
long long lnext() {
  long long x;
  cin >> x;
  return x;
}
int main() {
  cout.precision(20);
  ios_base::sync_with_stdio(false);
  int n = next(), m = next();
  vector<vector<int> > x(n, vector<int>(m));
  for (int i = 0; i < n; i++)
    for (int j = 0; j < m; j++) x[i][j] = next() - 1;
  bool ok = false;
  for (int i = 0; i < m; i++)
    for (int j = 0; j <= i; j++) {
      for (int t = 0; t < n; t++) swap(x[t][i], x[t][j]);
      bool good = true;
      for (int a = 0; a < n; a++) {
        int cnt = 0;
        for (int b = 0; b < m; b++)
          if (x[a][b] != b) cnt++;
        if (cnt > 2) good = false;
      }
      if (good) ok = true;
      for (int t = 0; t < n; t++) swap(x[t][i], x[t][j]);
    }
  if (ok)
    cout << "YES";
  else
    cout << "NO";
}
