#include <bits/stdc++.h>
using namespace std;
int n, m;
int a[55][55];
inline bool check(int x, int y) {
  for (int i = 1; i <= n; i++) {
    int cnt = 0;
    for (int j = 1; j <= m; j++) {
      int w;
      if (j == x)
        w = a[i][y];
      else if (j == y)
        w = a[i][x];
      else
        w = a[i][j];
      if (w != j) cnt++;
    }
    if (cnt != 0 && cnt != 2) return false;
  }
  return true;
}
inline int read() {
  int x = 0, f = 1;
  char ch = getchar();
  while (ch > '9' || ch < '0') {
    if (ch == '-') f = -1;
    ch = getchar();
    if (ch == -1) return 0;
  }
  while (ch >= '0' && ch <= '9') {
    x = x * 10 + ch - '0';
    ch = getchar();
  }
  return x * f;
}
inline void write(int x) {
  if (x < 0) {
    putchar('-');
    x = -x;
  }
  if (x >= 10) write(x / 10);
  putchar(x % 10 + '0');
}
int main() {
  n = read(), m = read();
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= m; j++) a[i][j] = read();
  for (int i = 1; i <= m; i++)
    for (int j = 1; j <= i; j++)
      if (check(i, j)) {
        puts("YES");
        return 0;
      }
  puts("NO");
  return 0;
}
