#include <bits/stdc++.h>
using namespace std;
const int INF = 1e9 + 5;
template <typename T>
void print(vector<T>& v) {
  cout << "[";
  for (int i = 0; i < v.size(); ++i) {
    cout << v[i];
    if (i != v.size() - 1) cout << ", ";
  }
  cout << "]\n";
}
template <typename T>
void print(set<T>& v) {
  cout << "[";
  for (auto it : v) {
    cout << it;
    if (it != *v.rbegin()) cout << ", ";
  }
  cout << "]\n";
}
template <typename T, typename S>
void print(map<T, S>& v) {
  for (auto it : v) cout << it.first << " : " << it.second << "\n";
}
template <typename T, typename S>
void print(pair<T, S>& v) {
  cout << "( " << v.first << ", " << v.second << " )" << '\n';
}
template <typename T>
void print(T x) {
  cout << x << '\n';
}
int n, m;
bool correctable(vector<vector<int> >& grid) {
  bool pos = 1;
  for (int k = 0; k < n; k++) {
    int displaced = 0;
    for (int l = 0; l < m; l++) {
      if (grid[l][k] != l + 1) {
        displaced++;
      }
    }
    if (displaced > 2) {
      pos = 0;
      break;
    }
  }
  return pos;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cin >> n >> m;
  vector<vector<int> > grid(m, vector<int>(n));
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      cin >> grid[j][i];
    }
  }
  if (correctable(grid)) {
    cout << "YES" << '\n';
    return 0;
  }
  for (int i = 0; i < m; i++) {
    for (int j = i + 1; j < m; j++) {
      swap(grid[i], grid[j]);
      if (correctable(grid)) {
        cout << "YES" << '\n';
        return 0;
      }
      swap(grid[i], grid[j]);
    }
  }
  cout << "NO" << '\n';
}
