#include <bits/stdc++.h>
const int inf = 0x3f3f3f3f, maxn = 1000000 + 5;
using namespace std;
int e[25][25];
int n, m;
int sum[25];
int t[25][25];
bool check() {
  for (int i = 1; i <= n; i++) {
    int sum2 = 0;
    for (int j = 1; j <= m; j++) {
      if (t[i][j] != j) {
        sum2++;
        if (sum2 > 2) return 0;
      }
    }
  }
  return 1;
}
int main() {
  while (~scanf("%d %d", &n, &m)) {
    memset(sum, 0, sizeof(sum));
    for (int i = 1; i <= n; i++) {
      for (int j = 1; j <= m; j++) {
        scanf("%d", &e[i][j]);
        if (e[i][j] != j) {
          sum[i]++;
        }
      }
    }
    bool flag = 0;
    for (int i = 1; i <= n; i++) {
      if (sum[i] > 2) {
        flag = 1;
        break;
      }
    }
    if (!flag) {
      puts("YES");
      continue;
    }
    flag = 0;
    for (int i = 1; i < m; i++) {
      for (int j = i + 1; j <= m; j++) {
        memcpy(t, e, sizeof(e));
        for (int k = 1; k <= n; k++) {
          swap(t[k][i], t[k][j]);
        }
        if (check()) {
          flag = 1;
          break;
        }
      }
      if (flag) break;
    }
    if (flag)
      puts("YES");
    else
      puts("NO");
  }
  return 0;
}
