#include <bits/stdc++.h>
using namespace std;
int mp[200][22][22], base[22][22];
int n, m;
int main() {
  cin >> n >> m;
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= m; j++) base[i][j] = j;
  int cnt = 0;
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= m; j++) cin >> mp[cnt][i][j];
  for (int i = 1; i <= m; i++)
    for (int j = i + 1; j <= m; j++) {
      cnt++;
      for (int r = 1; r <= n; r++) {
        for (int c = 1; c <= m; c++) {
          if (c == i)
            mp[cnt][r][c] = mp[0][r][j];
          else if (c == j)
            mp[cnt][r][c] = mp[0][r][i];
          else
            mp[cnt][r][c] = mp[0][r][c];
        }
      }
    }
  bool ok = false;
  for (int i = 0; i <= cnt; i++) {
    bool flag = true;
    for (int r = 1; r <= n; r++) {
      int tot = 0;
      for (int c = 1; c <= m; c++) {
        tot += (mp[i][r][c] != base[r][c]);
      }
      if (tot > 2) flag = false;
    }
    if (flag) ok = true;
  }
  if (ok)
    cout << "YES" << endl;
  else
    cout << "NO" << endl;
  return 0;
}
