#include <bits/stdc++.h>
using namespace std;
int n, m, a[25][25];
int check() {
  int i, j;
  for (i = 0; i < n; i++) {
    vector<int> now;
    for (j = 0; j < m; j++) now.push_back(a[i][j]);
    sort(now.begin(), now.end());
    int x = 0;
    for (j = 0; j < m; j++) {
      x += (now[j] != a[i][j]);
    }
    if (x > 2) return 0;
  }
  return 1;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(NULL);
  int i, j, k;
  cin >> n >> m;
  for (i = 0; i < n; i++)
    for (j = 0; j < m; j++) cin >> a[i][j];
  int flag = check();
  if (flag) {
    cout << "YES";
    return 0;
  }
  for (i = 0; i < m; i++) {
    for (j = i + 1; j < m; j++) {
      for (k = 0; k < n; k++) swap(a[k][i], a[k][j]);
      flag += check();
      for (k = 0; k < n; k++) swap(a[k][i], a[k][j]);
      if (flag) {
        cout << "YES";
        return 0;
      }
    }
  }
  cout << "NO";
  return 0;
}
