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