#include <bits/stdc++.h>
using namespace std;
bool IsOk(int matrix[20][20], int n, int m) {
  int i, j, cnt;
  for (i = 0; i < n; i++) {
    cnt = 0;
    for (j = 0; j < m; j++) {
      if (matrix[i][j] != j + 1) {
        cnt++;
        if (cnt > 2) return false;
      }
    }
  }
  return true;
}
void SwapMatrixCols(int matrix[20][20], int c1, int c2, int n) {
  for (int i = 0; i < n; i++) swap(matrix[i][c1], matrix[i][c2]);
}
int main() {
  int n, m, i, j, k;
  cin >> n >> m;
  int matrix[20][20] = {0};
  int diff[20] = {0};
  int bruteforcelist[20];
  int brtcnt = 0;
  for (i = 0; i < n; i++) {
    for (j = 0; j < m; j++) {
      cin >> matrix[i][j];
      if (matrix[i][j] != j + 1) diff[j]++;
    }
  }
  j = 0;
  for (i = 0; i < m; i++) {
    if (diff[i] > 0) {
      bruteforcelist[j] = i;
      j++;
    }
  }
  if (IsOk(matrix, n, m)) {
    cout << "yes" << endl;
    return 0;
  } else {
    brtcnt = j;
    for (i = 0; i < brtcnt - 1; i++)
      for (j = i + 1; j < brtcnt; j++) {
        SwapMatrixCols(matrix, bruteforcelist[i], bruteforcelist[j], n);
        if (IsOk(matrix, n, m)) {
          cout << "yes" << endl;
          return 0;
        }
        SwapMatrixCols(matrix, bruteforcelist[i], bruteforcelist[j], n);
      }
  }
  cout << "No" << endl;
  return 0;
}
