#include <bits/stdc++.h>
using namespace std;
void convertfromstringtoint(char s, int &n) {
  stringstream ss;
  ss << s;
  ss >> n;
}
int arr[21][21];
int n;
void sswap(int j1, int j2) {
  for (int i = 1; i <= n; i++) {
    int t = arr[i][j1];
    arr[i][j1] = arr[i][j2];
    arr[i][j2] = t;
  }
}
int main() {
  int m;
  cin >> n >> m;
  if (n == m && n == 1) {
    cout << "YES";
    return 0;
  }
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= m; j++) cin >> arr[i][j];
  int p = 1;
  for (int k = 1; k < m;) {
    sswap(k, p);
    int sum = 0;
    for (int i = 1; i <= n; i++) {
      int x = 0;
      for (int j = 1; j <= m; j++) {
        if (arr[i][j] != j) x++;
      }
      if (x > 2)
        break;
      else
        sum++;
    }
    if (sum == n) {
      cout << "YES";
      return 0;
    }
    sswap(k, p);
    p++;
    if (p == m + 1) {
      k++;
      p = k + 1;
    }
  }
  cout << "NO";
  return 0;
}
