#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  cin >> n >> m;
  vector<vector<int>> a(n, vector<int>(m));
  for (int i = 0; i < n; i += 1) {
    for (int j = 0; j < m; j += 1) {
      cin >> a[i][j];
    }
  }
  for (int i = 0; i < m; i += 1) {
    for (int j = i + 1 - !i; j < m; j += 1) {
      vector<vector<int>> t = a;
      for (int k = 0; k < n; k += 1) {
        swap(t[k][i], t[k][j]);
      }
      bool ok = true;
      for (int k = 0; k < n; k += 1) {
        bool row_op = false;
        for (int p = 0; p < m; p += 1) {
          bool swapped = false;
          int best = p;
          for (int q = p + 1; q < m; q += 1) {
            if (t[k][q] < t[k][best]) {
              best = q;
              swapped = true;
            }
          }
          if (swapped == true) {
            swap(t[k][best], t[k][p]);
            if (row_op == false) {
              row_op = true;
            } else {
              ok = false;
            }
          }
        }
        if (ok == false) {
          break;
        }
      }
      if (ok == true) {
        cout << "YES\n";
        return 0;
      }
    }
  }
  cout << "NO\n";
  return 0;
}
