#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  cin >> n >> m;
  int a[n][m], b[n][m];
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) cin >> a[i][j];
  }
  for (int k = 0; k < m; k++) {
    for (int l = k; l < m; l++) {
      for (int i = 0; i < n; i++)
        for (int j = 0; j < m; j++) b[i][j] = a[i][j];
      for (int i = 0; i < n; i++) {
        swap(b[i][k], b[i][l]);
      }
      bool c = 1;
      for (int i = 0; i < n; i++) {
        int sm = 0;
        for (int j = 0; j < m; j++) {
          if (b[i][j] != j + 1) sm++;
        }
        if (sm > 2) {
          c = 0;
          break;
        }
      }
      if (c) {
        cout << "YES";
        return 0;
      }
    }
  }
  cout << "NO";
  return 0;
}
