#include <bits/stdc++.h>
using namespace std;
template <typename T>
inline void gn(T &x) {
  x = 0;
  T f = 1;
  char ch = getchar();
  while (!isdigit(ch)) {
    if (ch == '-') f = -1;
    ch = getchar();
  }
  while (isdigit(ch)) {
    x = x * 10 + ch - '0';
    ch = getchar();
  }
  x *= f;
}
template <typename T>
inline void gt(T x) {
  if (!x) return;
  gt(x / 10);
  putchar(x % 10 + '0');
}
const long long MAXN = 1e6 + 10;
long long t, n, m, q, ans;
long long MOD = 1e9 + 7, inf = 0x1f1f1f1f;
double eps = 1e-5;
long long f[33][33], g[33];
void change(long long x, long long y) {
  long long i, j, k, l;
  for (i = 1; i <= n; i++) swap(f[i][x], f[i][y]);
}
long long check() {
  long long i, j, k, l;
  memset(g, 0, sizeof(g));
  for (i = 1; i <= n; i++) {
    for (j = 1; j <= m; j++) g[i] += (f[i][j] != j);
    if (g[i] != 0 && g[i] != 2) return 0;
  }
  return 1;
}
int main() {
  long long i, j, k, l, ca = 0;
  cin >> n >> m;
  for (i = 1; i <= n; i++)
    for (j = 1; j <= m; j++) cin >> f[i][j];
  ans = check();
  if (ans) return cout << "YES" << endl, 0;
  for (i = 1; i <= m; i++)
    for (j = i + 1; j <= m; j++) {
      change(i, j);
      ans = check();
      if (ans) return cout << "YES" << endl, 0;
      change(i, j);
    }
  cout << "NO" << endl;
  return 0;
}
