#include <bits/stdc++.h>
using namespace std;
int dp[200000 + 10];
int num[30][30];
int main(void) {
  int n, m;
  while (~scanf("%d%d", &n, &m)) {
    int flag = 1;
    for (int i = 1; i <= n; i++) {
      int k = 0;
      for (int j = 1; j <= m; j++) {
        scanf("%d", &num[i][j]);
        if (num[i][j] != j) k++;
      }
      if (k > 2) {
        flag = 0;
      }
    }
    if (flag) {
      puts("YES");
      continue;
    }
    for (int i = 1; i <= m; i++) {
      for (int j = 1; j <= m; j++) {
        if (i == j) continue;
        int f1 = 1;
        for (int k = 1; k <= n; k++) {
          int p = 0;
          for (int l = 1; l <= m; l++) {
            if (l == i) {
              if (num[k][l] == j)
                continue;
              else
                p++;
            } else if (l == j) {
              if (num[k][l] == i)
                continue;
              else
                p++;
            } else if (num[k][l] != l)
              p++;
          }
          if (p > 2) {
            f1 = 0;
            break;
          }
        }
        if (f1) {
          flag = 1;
          break;
        }
      }
      if (flag) {
        break;
      }
    }
    if (flag)
      puts("YES");
    else
      puts("NO");
  }
  return 0;
}
