#include <bits/stdc++.h>
using namespace std;
vector<vector<int> > v, original;
int n, m;
bool right() {
  for (int i = 0; i < m; i++) {
    for (int j = 0; j < n; j++) {
      if (v[i][j] != i + 1) {
        return false;
      }
    }
  }
}
int main() {
  cin >> n >> m;
  v.resize(m, vector<int>(n));
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      cin >> v[j][i];
    }
  }
  original = v;
  for (int i = 0; i < m; i++) {
    for (int j = i; j < m; j++) {
      v = original;
      swap(v[i], v[j]);
      for (int k = 0; k < n; k++) {
        for (int l = 0; l < m; l++) {
          if (v[l][k] != l + 1) {
            bool found = false;
            for (int w = l; w < m; w++) {
              if (v[w][k] == l + 1) {
                found = true;
                swap(v[w][k], v[l][k]);
                break;
              }
            }
            break;
          }
        }
      }
      if (right()) {
        cout << "YES";
        return 0;
      }
    }
  }
  cout << "NO";
  return 0;
}
