#include <bits/stdc++.h>
using namespace std;
int T[20][20];
int goal[20];
int N, M;
bool can() {
  for (int i = 0; i < (N); ++i) {
    int wrong = 0;
    for (int j = 0; j < (M); ++j)
      if (T[i][j] != goal[j]) ++wrong;
    if (wrong > 2) return false;
  }
  return true;
}
int main() {
  ios_base::sync_with_stdio(0);
  scanf("%d%d", &N, &M);
  for (int i = 0; i < (N); ++i)
    for (int j = 0; j < (M); ++j) scanf("%d", &T[i][j]);
  for (int i = 0; i < (M); ++i) goal[i] = i + 1;
  bool ok = can();
  for (int j = 0; j < (M); ++j)
    for (int k = 0; k < (j); ++k) {
      swap(goal[j], goal[k]);
      if (can()) ok = true;
      swap(goal[j], goal[k]);
    }
  printf(ok ? "YES\n" : "NO\n");
}
