#include <bits/stdc++.h>
using namespace std;
template <class T1, class T2>
bool upmin(T1 &x, T2 v) {
  if (x > v) {
    x = v;
    return true;
  }
  return false;
}
template <class T1, class T2>
bool upmax(T1 &x, T2 v) {
  if (x < v) {
    x = v;
    return true;
  }
  return false;
}
int N, M;
int G[30][30];
bool judge() {
  bool z = 0;
  for (int i = 0; i < N; ++i) {
    int tag = 0;
    for (int j = 0; j < M; ++j) {
      for (int k = j; k <= M - 1; ++k) {
        swap(G[i][j], G[i][k]);
        int f = 0;
        for (int l = 0; l < M; ++l)
          if (G[i][l] != l + 1) f = 1;
        if (not f) tag = 1;
        swap(G[i][j], G[i][k]);
      }
    }
    if (not tag) z = 1;
  }
  return not z;
}
bool ok(int x, int y) {
  for (int i = 0; i < N; ++i) swap(G[i][x], G[i][y]);
  bool res = judge();
  for (int i = 0; i < N; ++i) swap(G[i][x], G[i][y]);
  return res;
}
void solve() {
  cin >> N >> M;
  for (int i = 0; i < N; ++i)
    for (int j = 0; j < M; ++j) cin >> G[i][j];
  int ans = 0;
  for (int i = 0; i < M; ++i)
    for (int j = i; j <= M - 1; ++j)
      if (ok(i, j)) ans = 1;
  if (ans)
    cout << "YES\n";
  else
    cout << "NO\n";
}
int main() {
  ios::sync_with_stdio(false);
  solve();
  return 0;
}
