#include <bits/stdc++.h>
long long int INF = pow(10, 10);
using namespace std;
map<int, int> primefacs(long long x) {
  map<int, int> facs;
  long long myx = x;
  for (int i = 2; i < int(sqrt(x)) + 1; i++) {
    if (x % i == 0) {
      int cnt = 0;
      while (x % i == 0) {
        cnt += 1;
        x = x / i;
      }
      facs.insert({i, cnt});
    }
  }
  if (x >= 2) {
    facs.insert({x, 1});
  }
  return facs;
}
int n, m;
long long int cnt = 0;
bool isposs(int arr[][100], int i, int j) {
  for (int k = 0; k < n; k++) {
    swap(arr[k][i], arr[k][j]);
  }
  for (int k = 0; k < n; k++) {
    int disorderd = 0;
    for (int l = 0; l < m; l++) {
      if (arr[k][l] != (l + 1)) disorderd += 1;
    }
    if (disorderd > 2) return false;
  }
  return true;
}
void solution() {
  cin >> n >> m;
  int arr[n][m];
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) cin >> arr[i][j];
  };
  int myarr[n][100];
  for (int i = 0; i < m; i++) {
    for (int j = 0; j < m; j++) {
      for (int k = 0; k < n; k++) {
        for (int l = 0; l < m; l++) myarr[k][l] = arr[k][l];
      }
      if (isposs(myarr, i, j) == true) {
        cout << "YES" << endl;
        return;
      }
    }
  }
  cout << "NO" << endl;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int p = 1;
  while (p--) {
    solution();
  }
  return 0;
}
