#include <bits/stdc++.h>
using namespace std;
int a[25][25];
void Rd(int &res) {
  char c;
  res = 0;
  int k = 1;
  while (c = getchar(), !isdigit(c) && c != '-')
    ;
  if (c == '-') {
    k = -1;
    c = '0';
  }
  do {
    res = (res << 3) + (res << 1) + (c ^ 48);
  } while (c = getchar(), isdigit(c));
  res *= k;
}
void print(int x) {
  if (x == 0) return;
  print(x / 10);
  putchar(x % 10 ^ 48);
}
void Pf(int x) {
  if (x < 0) {
    putchar('-');
    x = -x;
  }
  print(x);
  if (x == 0) putchar('0');
  puts("");
}
void swap(int &a, int &b) {
  int tmp = a;
  a = b;
  b = tmp;
}
int n, m;
bool check() {
  int J1, J2;
  for (int i = 1; i <= n; i++) {
    int c = 0;
    for (int j = 1; j <= m; j++)
      if (a[i][j] != j) c++;
    if (c != 2 && c != 0) return false;
  }
  return true;
}
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]);
  for (int i = 1; i <= m; i++) {
    for (int j = 1; j <= m; j++) {
      for (int k = 1; k <= n; k++) swap(a[k][i], a[k][j]);
      if (check()) {
        puts("YES");
        return 0;
      }
      for (int k = 1; k <= n; k++) swap(a[k][i], a[k][j]);
    }
  }
  puts("NO");
  return 0;
}
