#include <bits/stdc++.h>
using namespace std;
int n, m, a[22][22];
int main(int argc, char **argv) {
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= n; ++i)
    for (int j = 1; j <= m; ++j) scanf("%d", &a[i][j]);
  for (int x = 1; x <= m; ++x)
    for (int y = x; y <= m; ++y) {
      for (int i = 1; i <= n; ++i) swap(a[i][x], a[i][y]);
      bool f = 1;
      for (int i = 1; i <= n; ++i) {
        int c = 0;
        for (int j = 1; j <= m; ++j)
          if (a[i][j] != j) ++c;
        if (c != 2 && c != 0) {
          f = 0;
          break;
        }
      }
      if (f) return puts("YES"), 0;
      for (int i = 1; i <= n; ++i) swap(a[i][x], a[i][y]);
    }
  puts("NO");
  return 0;
}
