#include <bits/stdc++.h>
using namespace std;
const int N = 25;
int n, m, a[N][N], b[N];
void make(int x, int y) {
  for (int i = 1; i <= m; i++) b[i] = i;
  swap(b[x], b[y]);
}
bool ok(int u[]) {
  int dif = 0;
  for (int i = 1; i <= m; i++)
    if (u[i] != b[i]) dif++;
  return dif <= 2;
}
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= m; j++) scanf("%d", &a[i][j]);
  bool yes = 0;
  for (int i = 1; i <= m; i++) b[i] = i;
  bool o = 1;
  for (int i = 1; i <= n; i++) {
    if (!ok(a[i])) {
      o = 0;
      break;
    }
  }
  if (o) yes = 1;
  for (int i = 1; i <= m; i++) {
    for (int j = i + 1; j <= m; j++) {
      o = 1;
      make(i, j);
      for (int k = 1; k <= n; k++) {
        if (!ok(a[k])) {
          o = 0;
          break;
        }
      }
      if (o) yes = 1;
    }
  }
  puts(yes ? "YES" : "NO");
  return 0;
}
