#include <bits/stdc++.h>
int num[25][25], tmpn[25][25];
int allr, allc;
bool can, fin;
void recur(int nowr) {
  if (nowr > allr) {
    can = true;
    for (int i = 1; i <= allr; ++i) {
      for (int j = 1; j <= allc; ++j) {
        if (num[i][j] != j) can = false;
      }
    }
    if (can) fin = true;
    return;
  }
  bool al = false;
  for (int i = 1; i <= allc; ++i) {
    if (num[nowr][i] != i) {
      int temp = num[nowr][i];
      int a = i;
      int b = temp;
      num[nowr][i] = num[nowr][temp];
      num[nowr][temp] = temp;
      recur(nowr + 1);
      temp = num[nowr][a];
      num[nowr][a] = num[nowr][b];
      num[nowr][b] = temp;
      al = true;
      break;
    }
  }
  if (!al) recur(nowr + 1);
}
int main() {
  scanf("%d%d", &allr, &allc);
  for (int i = 1; i <= allr; ++i) {
    for (int j = 1; j <= allc; ++j) {
      scanf("%d", &num[i][j]);
      tmpn[i][j] = num[i][j];
    }
  }
  for (int i = 1; i <= allc; ++i) {
    for (int j = 1; j < i; ++j) {
      for (int r = 1; r <= allr; ++r) {
        int temp = num[r][i];
        num[r][i] = num[r][j];
        num[r][j] = temp;
      }
      recur(1);
      if (fin) {
        printf("YES\n");
        return 0;
      }
      for (int r = 1; r <= allr; ++r) {
        int temp = num[r][i];
        num[r][i] = num[r][j];
        num[r][j] = temp;
      }
    }
  }
  for (int i = 1; i <= allr; ++i) {
    for (int j = 1; j <= allc; ++j) {
      num[i][j] = tmpn[i][j];
    }
  }
  recur(1);
  if (fin == true) {
    printf("YES\n");
  } else
    printf("NO\n");
  return 0;
}
