#include <bits/stdc++.h>
using namespace std;
int n, m;
int a[25][25], tmp[25][25];
void swaap(int x, int y) {
  for (int i = 0; i < n; i++) swap(a[i][x], a[i][y]);
}
bool check() {
  for (int i = 0; i < n; i++) {
    int cnt = 0;
    for (int j = 1; j <= m; j++) {
      cnt += (a[i][j] != j);
    }
    if (cnt > 2) return false;
  }
  return true;
}
void resett() {
  for (int i = 0; i < n; i++) {
    for (int j = 1; j <= m; j++) a[i][j] = tmp[i][j];
  }
}
int main() {
  cin >> n >> m;
  for (int i = 0; i < n; i++)
    for (int j = 1; j <= m; j++) {
      cin >> a[i][j];
      tmp[i][j] = a[i][j];
    }
  if (check()) {
    puts("YES");
    return 0;
  }
  for (int i = 1; i <= m; i++) {
    for (int j = i + 1; j <= m; j++) {
      swaap(i, j);
      if (check()) {
        puts("YES");
        return 0;
      }
      resett();
    }
  }
  puts("NO");
}
