#include <bits/stdc++.h>
using namespace std;
int main() {
  int i, j, k, n, m, flag = 0, count1 = 0, x, y, a[100][100], l;
  cin >> n;
  cin >> m;
  for (i = 0; i < n; i++) {
    for (j = 0; j < m; j++) {
      cin >> a[i][j];
    }
  }
  for (i = 0; i < n; i++) {
    for (j = 0; j < m; j++) {
      if (a[i][j] != j + 1) {
        flag = 1;
        break;
      }
    }
  }
  if (flag == 0) {
    cout << "YES" << endl;
    return 0;
  } else {
    for (i = 0; i < m; i++) {
      for (l = i; l < m; l++) {
        flag = 0;
        for (j = 0; j < n; j++) {
          int temp = a[j][i];
          a[j][i] = a[j][l];
          a[j][l] = temp;
        }
        for (x = 0; x < n; x++) {
          count1 = 0;
          for (y = 0; y < m; y++) {
            if (a[x][y] != y + 1) {
              count1++;
            }
          }
          if (count1 > 2) {
            flag = 1;
            break;
          }
        }
        if (flag == 0) {
          printf("YES\n");
          return 0;
        }
        for (j = 0; j < m; j++) swap(a[j][i], a[j][l]);
      }
    }
  }
  cout << "NO" << endl;
  return 0;
}
