#include <bits/stdc++.h>
using namespace std;
const int oo = 0x3f3f3f3f;
int inp[22][22];
int mat[22][22];
void copy_mat(int n, int m) {
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < m; ++j) {
      mat[i][j] = inp[i][j];
    }
  }
}
int p[22];
void get_order(int m) {
  for (int i = 0; i < m; ++i) {
    for (int j = 0; j < m; ++j) {
      if (mat[0][j] == i) {
        p[i] = j;
        break;
      }
    }
  }
}
bool test(int n, int m) {
  for (int r = 0; r < n; ++r) {
    int wrong = 0;
    for (int c = 0; c < m; ++c) {
      if (mat[r][c] != c) ++wrong;
    }
    if (wrong > 2) {
      return false;
    }
  }
  return true;
}
int main() {
  int n, m;
  scanf("%d %d", &n, &m);
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < m; ++j) {
      scanf("%d", &inp[i][j]);
      --inp[i][j];
    }
  }
  copy_mat(n, m);
  if (test(n, m)) {
    printf("YES\n");
    return 0;
  }
  for (int i = 0; i < m; ++i) {
    for (int j = i + 1; j < m; ++j) {
      copy_mat(n, m);
      for (int k = 0; k < n; ++k) {
        swap(mat[k][i], mat[k][j]);
      }
      if (test(n, m)) {
        printf("YES\n");
        return 0;
      }
    }
  }
  printf("NO\n");
  return 0;
}
