#include <bits/stdc++.h>
using namespace std;
int main() {
  long n, m;
  cin >> n >> m;
  long arr[101][101];
  long temp[101][101];
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++) {
      cin >> arr[i][j];
    }
  }
  for (int i = 1; i <= m; i++) {
    for (int j = i; j <= m; j++) {
      bool flag = false;
      for (int k = 1; k <= n; k++) {
        int kk = temp[k][i];
        temp[k][i] = temp[k][j];
        temp[k][j] = kk;
      }
      for (int v = 1; v <= n; v++) {
        int cnt = 0;
        for (int x = 1; x <= m; x++) {
          if (temp[v][x] != x) cnt++;
        }
        if (cnt > 2) flag = true;
      }
      if (flag == false) {
        cout << "YES";
        return 0;
      }
      for (int v = 1; v <= n; v++) {
        for (int x = 1; x <= m; x++) temp[v][x] = arr[v][x];
      }
    }
  }
  cout << "NO";
  return 0;
}
