#include <bits/stdc++.h>
using namespace std;
int n, m;
int mp[22][22];
bool vis[22];
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= m; j++) scanf("%d", &mp[i][j]);
  bool flag = 0;
  int num = 0;
  bool flag2 = 1;
  for (int j1 = 1; j1 <= m; j1++) {
    for (int j2 = j1; j2 <= m; j2++) {
      int cur;
      for (int i = 1; i <= n; i++) swap(mp[i][j1], mp[i][j2]);
      for (int i = 1; i <= n; i++) {
        num = 0, flag2 = 1;
        for (int j = 1; j <= m; j++)
          if (mp[i][j] != j) num++;
        if (num > 2) {
          flag2 = 0;
          break;
        }
      }
      for (int i = 1; i <= n; i++) swap(mp[i][j1], mp[i][j2]);
      if (flag2) flag = 1;
    }
  }
  printf("%s\n", flag ? "YES" : "NO");
}
