#include <bits/stdc++.h>
const double PI = acos(-0);
const int mod = 1000007;
const int maxn = 100;
const int inf = 2e9;
const int NEXT[][2] = {{-1, 0}, {1, 0}, {0, -1}, {0, 1}};
using namespace std;
int a[maxn][maxn];
int b[maxn][maxn];
int n, m;
bool judge() {
  for (int i = 1; i <= n; i++) {
    int temp = 0;
    for (int j = 1; j <= m; j++) {
      if (a[i][j] != j) temp++;
    }
    if (temp > 2) return 0;
  }
  return 1;
}
bool judge2() {
  for (int i = 1; i <= n; i++) {
    int temp = 0;
    for (int j = 1; j <= m; j++) {
      if (b[i][j] != j) temp++;
    }
    if (temp > 2) return 0;
  }
  return 1;
}
int main() {
  while (scanf("%d%d", &n, &m) != EOF) {
    memset((a), (0), (sizeof(a)));
    for (int i = 1; i <= n; i++) {
      for (int j = 1; j <= m; j++) {
        scanf("%d", &a[i][j]);
      }
    }
    if (judge())
      printf("YES\n");
    else {
      bool flag = 0;
      for (int i = 1; i <= m; i++) {
        for (int j = i + 1; j <= m; j++) {
          memcpy(b, a, sizeof a);
          for (int k = 1; k <= n; k++) {
            swap(b[k][i], b[k][j]);
          }
          if (judge2()) {
            flag = 1;
            break;
          }
        }
        if (flag) break;
      }
      if (flag)
        printf("YES\n");
      else
        printf("NO\n");
    }
  }
}
