#include <bits/stdc++.h>
using namespace std;
int a[30][30], c[30][30], n, m;
vector<pair<int, int> > v;
bool cmp(pair<int, int> x, pair<int, int> y) { return x.first < y.first; }
void swp(int x, int y) {
  int i;
  for (i = 0; i < n; i++) swap(a[i][x], a[i][y]);
}
int main() {
  int i, j, cn, z = 0, x = 0, y = 1;
  scanf("%d%d", &n, &m);
  for (i = 0; i < n; i++)
    for (j = 0; j < m; j++) scanf("%d", &a[i][j]), c[i][j] = a[i][j];
  while (1) {
    z = 0;
    for (i = 0; i < n; i++) {
      v.clear();
      for (j = 0; j < m; j++) {
        v.push_back(pair<int, int>(a[i][j], j));
      }
      sort(v.begin(), v.end(), cmp);
      cn = 0;
      for (j = 0; j < v.size(); j++) {
        if (v[j].second != j) {
          cn++;
        }
      }
      if (cn > 2) {
        z = 1;
        break;
      }
    }
    if (z == 0) break;
    for (i = 0; i < n; i++)
      for (j = 0; j < m; j++) a[i][j] = c[i][j];
    swp(x, y);
    y++;
    if (y >= m) x++, y = x + 1;
    if (x == m) break;
  }
  if (z == 1)
    cout << "NO";
  else
    cout << "YES";
  cout << "\n";
  return 0;
}
