#include <bits/stdc++.h>
using namespace std;
int m, n, a[22][22];
int main() {
  scanf("%d%d", &m, &n);
  for (int i = 1; i <= m; ++i)
    for (int j = 1; j <= n; ++j) scanf("%d", &a[i][j]);
  bool ok = 1;
  for (int i = 1; i <= m; ++i) {
    int cnt = 0;
    for (int j = 1; j <= n; ++j)
      if (a[i][j] != j) ++cnt;
    if (cnt > 2) ok = 0;
  }
  if (ok) return puts("YES");
  for (int c1 = 1; c1 <= n; ++c1)
    for (int c2 = c1 + 1; c2 <= n; ++c2) {
      ok = 1;
      for (int i = 1; i <= m; ++i) {
        int cnt = 0;
        for (int j = 1; j <= n; ++j) {
          if (j == c1 || j == c2) continue;
          if (a[i][j] != j) ++cnt;
        }
        if (a[i][c1] != c2) ++cnt;
        if (a[i][c2] != c1) ++cnt;
        if (cnt > 2) ok = 0;
      }
      if (ok) return puts("YES");
    }
  puts("NO");
}
