#include <bits/stdc++.h>
using namespace std;
int a[25][25], cnt, n, m;
bool judge() {
  for (int i = 0; i < n; i++) {
    cnt = 0;
    for (int j = 0; j < m; j++) cnt += (a[i][j] != j + 1);
    if (cnt > 2) return 0;
  }
  return 1;
}
int main() {
  cin >> n >> m;
  for (int i = 0; i < n; i++)
    for (int j = 0; j < m; j++) scanf("%d", &a[i][j]);
  bool ans = judge();
  if (ans) {
    puts("YES");
    return 0;
  } else {
    for (int i = 0; i < m; i++)
      for (int j = i + 1; j < m; j++) {
        for (int k = 0; k < n; k++) swap(a[k][i], a[k][j]);
        ans = judge();
        if (ans) {
          puts("YES");
          return 0;
        }
        for (int k = 0; k < n; k++) swap(a[k][i], a[k][j]);
      }
  }
  puts("NO");
}
