#include <bits/stdc++.h>
using namespace std;
int Map[30][30];
int N, M, T;
void Swap(int x, int y) {
  for (int i = 1; i <= N; i++) {
    swap(Map[i][x], Map[i][y]);
  }
}
bool Find() {
  int ans = 0;
  for (int i = 1; i <= N; i++) {
    int s = 0;
    for (int j = 1; j <= M; j++) {
      if (Map[i][j] != j) s++;
    }
    if (s > 2) return 0;
  }
  return 1;
}
int main() {
  cin >> N;
  cin >> M;
  for (int i = 1; i <= N; i++)
    for (int j = 1; j <= M; j++) scanf("%d", &Map[i][j]);
  int flag = 0;
  if (Find()) flag = 1;
  for (int i = 1; i <= M; i++) {
    for (int j = i + 1; j <= M; j++) {
      if (i == j) continue;
      Swap(i, j);
      if (Find()) {
        flag = 1;
        break;
      }
      Swap(i, j);
    }
    if (flag) break;
  }
  if (flag)
    cout << "YES\n";
  else
    cout << "NO\n";
  return 0;
}
