#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  cin >> n >> m;
  vector<vector<int>> a(m, vector<int>(n));
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      cin >> a[j][i];
    }
  }
  vector<vector<int>> b;
  for (int p = 0; p < m; p++) {
    for (int q = p; q < m; q++) {
      b = a;
      swap(b[p], b[q]);
      bool f = true;
      for (int i = 0; i < n; i++) {
        int k = 0;
        for (int j = 0; j < m; j++) {
          if (b[j][i] != j + 1) k++;
        }
        if (k > 2) f = false;
      }
      if (f) {
        cout << "YES";
        return 0;
      }
    }
  }
  cout << "NO";
}
