#include <bits/stdc++.h>
using namespace std;
int matrix[21][21];
void swap(int *x, int *y) {
  int tp = *x;
  *x = *y;
  *y = tp;
}
bool countLines(int N, int M) {
  int contador, status = 0;
  for (int i = 1; i <= N; ++i) {
    contador = 0;
    for (int j = 1; j <= M; ++j) {
      if (matrix[i][j] != j) contador++;
    }
    if (contador > 2) {
      status = 1;
    }
  }
  if (status == 0)
    return true;
  else
    return false;
}
void orderPermutation(int N, int M) {
  for (int k = 1; k <= M; ++k) {
    for (int i = 1; i <= M; ++i) {
      if (k != i) {
        for (int j = 1; j <= N; ++j) {
          swap(&matrix[j][k], &matrix[j][i]);
        }
        if (countLines(N, M)) {
          printf("YES\n");
          return;
        } else {
          for (int j = 1; j <= N; ++j) {
            swap(&matrix[j][k], &matrix[j][i]);
          }
        }
      }
    }
  }
  printf("NO\n");
}
int main(void) {
  int N, M;
  while (scanf("%d %d", &N, &M) == 2) {
    for (int i = 1; i <= N; ++i) {
      for (int j = 1; j <= M; ++j) {
        scanf("%d", &matrix[i][j]);
      }
    }
    if (countLines(N, M))
      printf("YES\n");
    else
      orderPermutation(N, M);
  }
  return 0;
}
