#include <bits/stdc++.h>
using namespace std;
int s[25][25], ys[25][25];
int n, m;
bool check() {
  for (int i = 1; i <= (n); i++) {
    int num = 0;
    for (int j = 1; j <= (m); j++) {
      if (s[i][j] != j) num++;
    }
    if (num > 2) return false;
  }
  return true;
}
void swapc(int a, int b) {
  for (int i = 1; i <= (n); i++)
    for (int j = 1; j <= (m); j++) s[i][j] = ys[i][j];
  for (int i = 1; i <= (n); i++) swap(s[i][a], s[i][b]);
}
int main() {
  while (cin >> n >> m) {
    bool f = 0;
    for (int i = 1; i <= (n); i++)
      for (int j = 1; j <= (m); j++) cin >> ys[i][j];
    swapc(1, 1);
    if (check())
      f = 1;
    else {
      for (int i = 1; i <= (m); i++)
        for (int j = 1; j <= (i); j++) {
          swapc(i, j);
          if (check()) f = 1;
        }
    }
    if (f)
      cout << "YES" << endl;
    else
      cout << "NO" << endl;
  }
  return 0;
}
