#include <bits/stdc++.h>
using namespace std;
vector<vector<int>> change(vector<vector<int>> v, int a, int b) {
  for (int i = 0; i < v.size(); i++) {
    swap(v[i][a], v[i][b]);
  }
  return v;
}
bool possible(vector<vector<int>>& v) {
  for (int i = 0; i < v.size(); i++) {
    int diff = 0;
    vector<int> orig = v[i];
    vector<int> clone = v[i];
    sort(clone.begin(), clone.end());
    for (int j = 0; j < orig.size(); j++)
      if (orig[j] != clone[j]) diff++;
    if (diff > 2) return false;
  }
  return true;
}
int main() {
  int n, m;
  cin >> n >> m;
  vector<vector<int>> v(n, vector<int>(m));
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) cin >> v[i][j];
  }
  if (possible(v)) {
    cout << "YES\n";
    return 0;
  }
  for (int a = 0; a < m; a++) {
    for (int b = a + 1; b < m; b++) {
      auto k = change(v, a, b);
      if (possible(k)) {
        cout << "YES\n";
        return 0;
      }
    }
  }
  cout << "NO\n";
}
