#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m, i, j, k, l, cnt;
  int shu[25][25], shu2[25][25];
  bool flag;
  cin >> n >> m;
  for (i = 1; i <= n; i++)
    for (j = 1; j <= m; j++) cin >> shu[i][j];
  flag = true;
  for (i = 1; i <= n; i++) {
    cnt = 0;
    for (j = 1; j <= m; j++)
      if (shu[i][j] != j) cnt++;
    if (cnt > 2) flag = false;
  }
  if (flag) {
    cout << "YES" << endl;
    return 0;
  }
  for (i = 1; i <= m - 1; i++)
    for (j = i + 1; j <= m; j++) {
      for (k = 1; k <= n; k++)
        for (l = 1; l <= m; l++) {
          if (l == i)
            shu2[k][l] = shu[k][j];
          else if (l == j)
            shu2[k][l] = shu[k][i];
          else
            shu2[k][l] = shu[k][l];
        }
      flag = true;
      for (k = 1; k <= n; k++) {
        cnt = 0;
        for (l = 1; l <= m; l++)
          if (shu2[k][l] != l) cnt++;
        if (cnt > 2) flag = false;
      }
      if (flag) {
        cout << "YES" << endl;
        return 0;
      }
    }
  cout << "NO" << endl;
  return 0;
}
