#include <bits/stdc++.h>
using namespace std;
void YES() {
  cout << "YES\n";
  exit(0);
}
void NO() {
  cout << "NO\n";
  exit(0);
}
int MS[200][200];
void readAndWork(int num, int m) {
  vector<int> a(m);
  for (int i = 0; i < m; ++i) cin >> a[i];
  vector<int> res1, res2;
  for (int i = 0; i < m; ++i) res1.push_back(i + 1);
  res2 = res1;
  for (int i = 0; i < m; ++i)
    for (int j = i; j < m; ++j) {
      swap(a[i], a[j]);
      int kol = 0;
      for (int k = 0; k < m; ++k)
        if (a[k] != k + 1) ++kol;
      if (kol <= 2) {
        MS[i][j] |= (1 << num);
      }
      swap(a[i], a[j]);
      swap(res2[i], res2[j]);
      for (int i1 = 0; i1 < m; ++i1)
        for (int i2 = i1 + 1; i2 < m; ++i2) {
          swap(a[i1], a[i2]);
          if (a == res2) {
            MS[i][j] |= (1 << num);
          }
          swap(a[i1], a[i2]);
        }
      swap(res2[i], res2[j]);
    }
}
int main() {
  ios_base::sync_with_stdio(0);
  int n, m;
  cin >> n >> m;
  memset(MS, 0, sizeof(MS));
  for (int i = 0; i < n; ++i) readAndWork(i, m);
  vector<int> res;
  for (int i = 0; i < m; ++i) res.push_back(i + 1);
  for (int i = 0; i < m; ++i)
    for (int j = i; j < m; ++j)
      if (MS[i][j] == (1 << n) - 1) YES();
  NO();
  return 0;
}
