#include <bits/stdc++.h>
const int INF = 1e9 + 7;
const long long INFLL = 1e16;
const double EPS = 1e-6;
using namespace std;
int arr[25][25];
int n, m;
int now[25][25];
int main() {
  scanf("%d%d", &n, &m);
  for (int k = (int)0; k < (int)n; k++)
    for (int i = (int)0; i < (int)m; i++) scanf("%d", &arr[k][i]);
  int ret = 0;
  for (int c1 = (int)0; c1 < (int)m; c1++)
    for (int c2 = (int)0; c2 < (int)m; c2++) {
      for (int k = (int)0; k < (int)n; k++)
        for (int i = (int)0; i < (int)m; i++) now[k][i] = arr[k][i];
      for (int k = (int)0; k < (int)n; k++) swap(now[k][c1], now[k][c2]);
      int bisa = 1;
      for (int k = (int)0; k < (int)n; k++) {
        int cnt = 0;
        for (int i = (int)0; i < (int)m; i++) {
          if (now[k][i] != i + 1) cnt++;
        }
        if (cnt > 2) bisa = 0;
      }
      if (bisa) ret = 1;
    }
  if (ret)
    printf("YES\n");
  else
    printf("NO\n");
  return 0;
}
