#include <bits/stdc++.h>
int a[25][25], n, m;
bool check(int x, int y) {
  for (int i = 0; i < n; i++) {
    int wr = 0;
    for (int j = 0; j < m; j++) {
      if (j == x) {
        if (a[i][y] != j + 1) wr++;
      } else if (j == y) {
        if (a[i][x] != j + 1) wr++;
      } else {
        if (a[i][j] != j + 1) wr++;
      }
    }
    if (wr > 2) return false;
  }
  return true;
}
int main() {
  scanf("%d%d", &n, &m);
  bool ch1 = true;
  for (int i = 0; i < n; i++) {
    int wr = 0;
    for (int j = 0; j < m; j++) {
      scanf("%d", &a[i][j]);
      if (a[i][j] != j + 1) wr++;
    }
    if (wr > 2) ch1 = false;
  }
  if (ch1) {
    printf("YES\n");
    return 0;
  } else {
    bool ch2 = false;
    for (int i = 0; i < m - 1; i++) {
      if (ch2) break;
      for (int j = i + 1; j < m; j++) {
        if (check(i, j)) {
          ch2 = true;
          break;
        }
      }
    }
    if (ch2)
      printf("YES\n");
    else
      printf("NO\n");
  }
  return 0;
}
