#include <bits/stdc++.h>
using namespace std;
long long powmod(long long a, long long b, long long MOD) {
  long long res = 1;
  a %= MOD;
  for (; b; b >>= 1) {
    if (b & 1) res = res * a % MOD;
    a = a * a % MOD;
  }
  return res;
}
int n, m;
int board[20][20];
void ksswap(int c1, int c2) {
  for (int i = 0; i < n; ++i) {
    swap(board[i][c1], board[i][c2]);
  }
}
bool check(int r) {
  vector<int> v;
  for (int i = 0; i < m; ++i)
    if (board[r][i] != i + 1) v.push_back(i);
  if (v.empty()) return true;
  if (v.size() > 2) return false;
  if (board[r][v[0]] == v[1] + 1) return true;
  return false;
}
bool checkall() {
  bool ok = true;
  for (int k = 0; k < n; ++k)
    if (!check(k)) {
      ok = false;
      break;
    }
  return ok;
}
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 0; i < n; ++i)
    for (int j = 0; j < m; ++j) scanf("%d", &board[i][j]);
  if (checkall()) {
    printf("YES\n");
    return 0;
  }
  for (int i = 0; i < m; ++i)
    for (int j = i + 1; j < m; ++j) {
      ksswap(i, j);
      if (checkall()) {
        printf("YES\n");
        return 0;
      }
      ksswap(i, j);
    }
  printf("NO\n");
  return 0;
}
