#include <bits/stdc++.h>
using namespace std;
int n, m;
int ar[30][30];
void swapcol(int x, int y) {
  for (int i = 1; i <= n; i++) {
    swap(ar[i][x], ar[i][y]);
  }
}
bool cek() {
  for (int i = 1; i <= n; i++) {
    vector<pair<int, int> > v;
    for (int j = 1; j <= m; j++)
      if (ar[i][j] != j) v.push_back({ar[i][j], j});
    if (v.size() != 0 and v.size() != 2) return false;
    if (v.size() == 0) continue;
    swap(v[0].first, v[0].second);
    if (v[0] != v[1]) return false;
  }
  return true;
}
int main() {
  ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  ;
  cin >> n >> m;
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= m; j++) cin >> ar[i][j];
  bool bisa = false;
  for (int i = 1; i <= m; i++)
    for (int j = i; j <= m; j++) {
      swapcol(i, j);
      bisa |= cek();
      swapcol(i, j);
    }
  cout << (bisa ? "YES" : "NO") << "\n";
}
