#include <bits/stdc++.h>
using namespace std;
int main() {
  map<string, long long> mp;
  string s1, s2;
  long long i, j, l, m, x = 0, y = 0, z, c = 0, ans = 0, ans_best, n, k,
                        count = 0, u, f = 0, t, p, q;
  float pi, s, v, o, h;
  long long a[50][50], temp[50][50];
  cin >> n >> m;
  for (i = 1; i <= n; i++) {
    count = 0;
    for (j = 1; j <= m; j++) {
      cin >> a[i][j];
      temp[i][j] = a[i][j];
    }
  }
  for (i = 1; i <= n; i++) {
    for (j = 1; j <= m; j++) {
      if (temp[i][j] != j) {
        for (k = j + 1; k <= m; k++) {
          if (temp[i][k] != k) {
            swap(temp[i][j], temp[i][k]);
            break;
          }
        }
        break;
      }
    }
  }
  count = 0;
  for (i = 1; i <= n; i++) {
    for (j = 1; j <= m; j++) {
      if (temp[i][j] == j) count++;
      temp[i][j] = a[i][j];
    }
  }
  if (count == n * m) f = 1;
  for (x = 1; x <= m; x++) {
    for (y = x + 1; y <= m; y++) {
      for (z = 1; z <= n; z++) swap(temp[z][x], temp[z][y]);
      for (i = 1; i <= n; i++) {
        for (j = 1; j <= m; j++) {
          if (temp[i][j] != j) {
            for (k = j + 1; k <= m; k++) {
              if (temp[i][k] != k) {
                swap(temp[i][j], temp[i][k]);
                break;
              }
            }
            break;
          }
        }
      }
      count = 0;
      for (i = 1; i <= n; i++) {
        for (j = 1; j <= m; j++) {
          if (temp[i][j] == j) count++;
          temp[i][j] = a[i][j];
        }
      }
      if (count == n * m) f = 1;
    }
  }
  if (f == 1)
    cout << "YES" << endl;
  else
    cout << "NO" << endl;
  return 0;
}
