#include <bits/stdc++.h>
using namespace std;
const int inf = (int)(1e9) + 100;
const int mod = (int)(1e9) + 100;
const int N = (int)(2e5) + 100;
int n, m;
int a[22][22];
vector<int> b[22];
int used[22][22];
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cin >> n >> m;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) cin >> a[i][j], b[i].push_back(a[i][j]);
    sort(b[i].begin(), b[i].end());
  }
  for (int i = 0; i < m; i++) {
    a[n][i] = i + 1;
  }
  int f = 1;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      if (a[i][j] == b[i][j]) continue;
      f = 0;
    }
  }
  if (f)
    return cout << "YES", 0;
  else {
    for (int i = 0; i < m; i++) {
      for (int j = 0; j < m; j++) {
        for (int k = 0; k < n; k++) {
          swap(a[k][i], a[k][j]);
        }
        int s = 1;
        for (int r = 0; r < n; r++) {
          int cnt = 0;
          for (int l = 0; l < m; l++) {
            if (a[r][l] != a[n][l]) cnt++;
          }
          if (cnt > 2) {
            s = 0;
            break;
          }
        }
        if (s) return cout << "YES\n", 0;
        for (int p = 0; p < n; p++) {
          swap(a[p][i], a[p][j]);
        }
      }
    }
    cout << "NO";
  }
  return 0;
}
