#include <bits/stdc++.h>
using namespace std;
const int maxn = 2e1 + 5;
int st[maxn][maxn];
int n, m;
bool ck() {
  for (int i = 1; i <= n; ++i) {
    int cnt = 0;
    for (int j = 1; j <= m; ++j) {
      if (st[i][j] != j) {
        ++cnt;
        if (cnt > 2) {
          return 0;
        }
      }
    }
  }
  return 1;
}
void cg(int x, int y) {
  for (int i = 1; i <= n; ++i) {
    swap(st[i][x], st[i][y]);
  }
}
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= n; ++i) {
    for (int j = 1; j <= m; ++j) {
      scanf("%d", &st[i][j]);
    }
  }
  if (ck()) {
    printf("YES\n");
    return 0;
  }
  for (int i = 1; i <= m; ++i) {
    for (int j = i + 1; j <= m; ++j) {
      cg(i, j);
      if (ck()) {
        printf("YES\n");
        return 0;
      }
      cg(i, j);
    }
  }
  printf("NO\n");
  return 0;
}
