#include <bits/stdc++.h>
using namespace std;
template <typename T>
T next_int() {
  T x = 0, p = 1;
  char ch;
  do {
    ch = getchar();
  } while (ch <= ' ');
  if (ch == '-') {
    p = -1;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9') {
    x = x * 10 + (ch - '0');
    ch = getchar();
  }
  return p * x;
}
string next_token() {
  char ch;
  string ans = "";
  do {
    ch = getchar();
  } while (ch <= ' ');
  while (ch > ' ') {
    ans += ch;
    ch = getchar();
  }
  return ans;
}
const long long INF = (long long)1e18;
const int INFINT = (int)1e9 + 227 + 1;
const int MAXN = (int)1e6 + 227 + 1;
const int MOD = (int)1e9 + 7;
const long double EPS = 1e-9;
long long bin_pow(long long a, long long b, int MOD) {
  if (!b) return 1;
  long long ans = bin_pow(a, b / 2, MOD);
  ans = ans * ans % MOD;
  if (b % 2) ans = ans * a % MOD;
  return ans;
}
bool check(vector<vector<int> > a) {
  int n = a.size();
  int m = a[0].size();
  for (int i = 0; i < n; i++) {
    vector<int> b = a[i];
    sort(b.begin(), b.end());
    int k = 0;
    for (int j = 0; j < m; j++) k += b[j] != a[i][j];
    if (k > 2) return 0;
  }
  return 1;
}
int main() {
  int n, m;
  cin >> n >> m;
  vector<vector<int> > a(n, vector<int>(m));
  for (int i = 0; i < n; i++)
    for (int j = 0; j < m; j++) cin >> a[i][j];
  if (check(a)) {
    puts("YES");
    return 0;
  }
  for (int i = 0; i < m; i++)
    for (int j = i + 1; j < m; j++) {
      for (int k = 0; k < n; k++) swap(a[k][i], a[k][j]);
      if (check(a)) {
        puts("YES");
        return 0;
      }
      for (int k = 0; k < n; k++) swap(a[k][i], a[k][j]);
    }
  puts("NO");
}
