#include <bits/stdc++.h>
using namespace std;
int a[25][25];
int n, m;
int check(int i) {
  int num = 0;
  for (int j = 0; j < m; j++)
    if (a[i][j] != (j + 1)) num++;
  if (num <= 2)
    return 1;
  else
    return 0;
}
int main() {
  cin >> n >> m;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) cin >> a[i][j];
  }
  int cc = 0;
  for (int i = 0; i < n; i++)
    if (!check(i)) {
      cc = 1;
      break;
    }
  if (!cc) {
    cout << "YES" << endl;
    return 0;
  }
  for (int i = 0; i < m; i++)
    for (int j = i + 1; j < m; j++) {
      int tmp;
      for (int k = 0; k < n; k++) {
        tmp = a[k][i];
        a[k][i] = a[k][j];
        a[k][j] = tmp;
      }
      int ok = 1;
      for (int k = 0; k < n; k++) {
        if (!check(k)) {
          ok = 0;
          break;
        }
      }
      if (ok) {
        cout << "YES" << endl;
        return 0;
      } else {
        for (int k = 0; k < n; k++) {
          tmp = a[k][i];
          a[k][i] = a[k][j];
          a[k][j] = tmp;
        }
      }
    }
  cout << "NO" << endl;
  return 0;
}
