#include <bits/stdc++.h>
using namespace std;
int n, m, a[111][111];
bool f, f1, f2;
int main(void) {
  cin >> n >> m;
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= m; j++) cin >> a[i][j];
  for (int x = 1; x <= m; x++)
    for (int y = x; y <= m; y++) {
      f = true;
      for (int d = 1; d <= n; d++) {
        f1 = false;
        swap(a[d][x], a[d][y]);
        for (int i = 1; i <= m; i++)
          for (int j = i; j <= m; j++)
            if (f1 == false) {
              swap(a[d][i], a[d][j]);
              f2 = true;
              for (int p = 1; p <= m; p++)
                if (a[d][p] != p) {
                  f2 = false;
                  break;
                }
              swap(a[d][i], a[d][j]);
              if (f2 == true) {
                f1 = true;
                break;
              }
            }
        swap(a[d][x], a[d][y]);
        if (f1 == false) {
          f = false;
          break;
        }
      }
      if (f == true) {
        cout << "YES" << endl;
        return 0;
      }
    }
  cout << "NO" << endl;
  return 0;
}
