#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:102400000,102400000")
template <class T>
inline void gmax(T &a, T b) {
  if (b > a) a = b;
}
template <class T>
inline void gmin(T &a, T b) {
  if (b < a) a = b;
}
using namespace std;
const int N = 1e5 + 10, M = 2e6 + 10, Z = 1e9 + 7, maxint = 2147483647,
          ms1 = 16843009, ms31 = 522133279, ms63 = 1061109567,
          ms127 = 2139062143;
const double PI = acos(-1.0), eps = 1e-8;
void fre() {
  freopen("/Users/luras/Desktop/in.txt", "r", stdin);
  freopen("/Users/luras/Desktop/out.txt", "w", stdout);
}
const int INF = 1e9;
int casenum, casei;
int n, m, a[30][30];
int main() {
  while (~scanf("%d%d", &n, &m)) {
    for (int i = 1; i <= n; i++) {
      for (int j = 1; j <= m; j++) {
        scanf("%d", &a[i][j]);
      }
    }
    int ans = 0;
    for (int i = 1; i <= m; i++) {
      for (int j = i + 1; j <= m; j++) {
        for (int k = 1; k <= n; k++) {
          swap(a[k][i], a[k][j]);
        }
        int flag = 1;
        for (int k = 1; k <= n; k++) {
          int num = 0;
          for (int l = 1; l <= m; l++) {
            if (a[k][l] != l) num++;
          }
          if (num > 2) {
            flag = 0;
            break;
          }
        }
        if (flag) ans = 1;
        for (int k = 1; k <= n; k++) {
          swap(a[k][i], a[k][j]);
        }
      }
    }
    int flag = 1;
    for (int k = 1; k <= n; k++) {
      int num = 0;
      for (int l = 1; l <= m; l++) {
        if (a[k][l] != l) num++;
      }
      if (num > 2) {
        flag = 0;
        break;
      }
    }
    if (flag) ans = 1;
    if (ans)
      puts("YES");
    else
      puts("NO");
  }
  return 0;
}
