#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  cin >> n >> m;
  int arr[n][m], arr2[n][m];
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      cin >> arr[i][j];
    }
  }
  for (int j = 0; j < m; j++) {
    for (int i = 0; i < m; i++) {
      for (int a = 0; a < n; a++) {
        for (int b = 0; b < m; b++) {
          if (b == i)
            arr2[a][b] = arr[a][j];
          else if (b == j)
            arr2[a][b] = arr[a][i];
          else
            arr2[a][b] = arr[a][b];
        }
      }
      int flag = 1;
      for (int a = 0; a < n; a++) {
        int ct = 0;
        for (int b = 0; b < m; b++) {
          if (arr2[a][b] != b + 1) {
            ct++;
          }
        }
        if (ct > 2) {
          flag = 0;
        }
      }
      if (flag == 1) {
        cout << "YES\n";
        return 0;
      }
    }
  }
  cout << "NO";
  return 0;
}
