#include <bits/stdc++.h>
using namespace std;
long long pwr(long long base, long long p, long long mod = (1000000007LL)) {
  long long ans = 1;
  while (p) {
    if (p & 1) ans = (ans * base) % mod;
    base = (base * base) % mod;
    p /= 2;
  }
  return ans;
}
int r, c, arr[22][22];
bool possible = false;
void validate(int i) {
  if (i == r + 1) {
    possible = true;
    return;
  }
  int l = -1, r = -1;
  for (int j = 1; j <= c; j++)
    if (arr[i][j] != j) {
      l = j;
      break;
    }
  for (int j = c; j >= 1; j--)
    if (arr[i][j] != j) {
      r = j;
      break;
    }
  if (l == -1)
    validate(i + 1);
  else {
    swap(arr[i][l], arr[i][r]);
    bool ok = true;
    for (int j = 1; j <= c; j++)
      if (arr[i][j] != j) ok = false;
    swap(arr[i][l], arr[i][r]);
    if (ok) validate(i + 1);
  }
}
int main() {
  ios_base::sync_with_stdio(0);
  cin >> r >> c;
  for (int i = 1; i <= r; i++)
    for (int j = 1; j <= c; j++) cin >> arr[i][j];
  for (int c1 = 1; c1 <= c; c1++)
    for (int c2 = c1; c2 <= c; c2++) {
      for (int i = 1; i <= r; i++) swap(arr[i][c1], arr[i][c2]);
      validate(1);
      for (int i = 1; i <= r; i++) swap(arr[i][c1], arr[i][c2]);
    }
  if (possible)
    cout << "YES";
  else
    cout << "NO";
  return 0;
}
