#include <bits/stdc++.h>
using namespace std;
const int N = 202;
int a[N][N];
int tmp[N][N];
int dp[N];
int main() {
  int n, m;
  while (scanf("%d%d", &n, &m) != EOF) {
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < m; j++) {
        scanf("%d", &a[i][j]);
        tmp[i][j] = a[i][j];
      }
    }
    int f = 0;
    for (int j = 0; !f && j < m; j++) {
      for (int k = 0; !f && k < m; k++) {
        for (int i = 0; i < n; i++) {
          swap(tmp[i][j], tmp[i][k]);
        }
        int flag = 1;
        for (int i = 0; i < n; i++) {
          int sum = 0;
          for (int p = 0; p < m; p++) {
            if (tmp[i][p] != p + 1) sum++;
          }
          if (sum == 0 || sum == 2)
            continue;
          else {
            flag = 0;
            break;
          }
        }
        if (flag) {
          f = 1;
        }
        for (int i = 0; i < n; i++) {
          swap(tmp[i][j], tmp[i][k]);
        }
      }
    }
    if (f)
      printf("YES\n");
    else
      printf("NO\n");
  }
  return 0;
}
