#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m, z[20][20], t[20][20];
  cin >> n >> m;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      cin >> z[i][j];
      z[i][j]--;
    }
  }
  for (int a = 0; a < m; a++) {
    for (int b = a; b < m; b++) {
      for (int i = 0; i < n; i++) {
        for (int j = 0; j < m; j++) {
          if (j == a) {
            t[i][j] = z[i][b];
            continue;
          }
          if (j == b) {
            t[i][j] = z[i][a];
            continue;
          }
          t[i][j] = z[i][j];
        }
      }
      int bi = 1;
      for (int c = 0; c < n; c++) {
        int q = 0;
        for (int d = 0; d < m; d++) {
          if (t[c][d] != d) q++;
        }
        if (q > 2) {
          bi = 0;
          break;
        }
      }
      if (bi == 1) {
        cout << "YES";
        return 0;
      }
    }
  }
  cout << "NO";
  return 0;
}
