#include <bits/stdc++.h>
using namespace std;
inline int Set(int N, int pos) { return N = N | (1 << pos); }
inline int Reset(int N, int pos) { return N = N & ~(1 << pos); }
inline bool check(int N, int pos) { return (bool)(N & (1 << pos)); }
template <class T>
T gcd(T a, T b) {
  return (!b) ? a : gcd(b, a % b);
}
template <class T>
T lcm(T a, T b) {
  return (a / gcd(a, b)) * b;
}
int a[22][22], b[22][22];
int n, m;
bool chk(int p, int q) {
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      b[i][j] = a[i][j];
    }
    swap(b[i][p], b[i][q]);
  }
  int d = 0;
  for (int i = 0; i < n; i++) {
    d = 0;
    for (int j = 0; j < m; j++) {
      if (b[i][j] != j + 1) d++;
    }
    if (d > 2) return 0;
  }
  return 1;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cin >> n >> m;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      cin >> a[i][j];
    }
  }
  if (chk(0, 0)) {
    cout << "YES" << endl;
    return 0;
  }
  for (int i = 0; i < m; i++) {
    for (int j = i + 1; j < m; j++) {
      if (chk(i, j)) {
        cout << "YES" << endl;
        return 0;
      }
    }
  }
  cout << "NO" << endl;
  return 0;
}
