#include <bits/stdc++.h>
using namespace std;
const int maxn = 100;
int n, m;
int a[maxn][maxn];
bool check() {
  for (int i = 1; i <= n; i++) {
    int tmp = 0;
    for (int j = 1; j <= m; j++) {
      if (a[i][j] != j) tmp++;
    }
    if (tmp > 2) return false;
  }
  return true;
}
int main() {
  scanf("%d %d", &n, &m);
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++) scanf("%d", &a[i][j]);
  }
  bool flag = 0;
  if (check() || m == 1) {
    puts("YES");
    return 0;
  } else
    for (int i = 1; i <= m; i++) {
      for (int j = i + 1; j <= m; j++) {
        for (int z = 1; z <= n; z++) swap(a[z][i], a[z][j]);
        if (check()) {
          puts("YES");
          return 0;
        }
        for (int z = 1; z <= n; z++) swap(a[z][i], a[z][j]);
      }
    }
  puts("NO");
  return 0;
}
