#include <bits/stdc++.h>
using namespace std;
int n, m;
int v[21][21];
int a[21][21];
bool f[21];
bool Work() {
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= m; j++) a[i][j] = v[i][j];
  memset(f, 0, sizeof(f));
  for (int j = 1; j <= m; j++) {
    for (int i = 1; i <= n; i++) {
      if (a[i][j] != j) {
        if (f[i]) return false;
        for (int k = j + 1; k <= m; k++) {
          if (a[i][k] == j) {
            swap(a[i][k], a[i][j]);
            f[i] = true;
            break;
          }
        }
      }
    }
  }
  return true;
}
int main() {
  bool flag;
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= m; j++) scanf("%d", &v[i][j]);
  flag = Work();
  for (int i = 1; i <= m; i++) {
    for (int j = i + 1; j <= m; j++) {
      for (int k = 1; k <= n; k++) swap(v[k][i], v[k][j]);
      flag |= Work();
      for (int k = 1; k <= n; k++) swap(v[k][i], v[k][j]);
    }
  }
  if (flag)
    printf("YES\n");
  else
    printf("NO\n");
  return 0;
}
