#include <bits/stdc++.h>
using namespace std;
int n, m, a[21][21];
void replace(int c, int b) {
  for (int i = 1; i <= n; i++) {
    swap(a[i][c], a[i][b]);
  }
}
bool check() {
  for (int i = 1; i <= n; i++) {
    int cnt = 0;
    for (int j = 1; j <= m; j++) {
      if (a[i][j] != j) cnt++;
    }
    if (cnt > 2) return false;
  }
  return true;
}
int main() {
  cin >> n >> m;
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++) {
      cin >> a[i][j];
    }
  }
  if (check()) {
    cout << "YES";
    return 0;
  } else {
    for (int i = 1; i < m; i++) {
      for (int j = i + 1; j <= m; j++) {
        replace(i, j);
        if (check()) {
          cout << "YES";
          return 0;
        }
        replace(i, j);
      }
    }
  }
  cout << "NO";
  return 0;
}
