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