#include <bits/stdc++.h>
using namespace std;
int getInt() {
  int x;
  scanf("%d", &x);
  return x;
}
long long getLongLong() {
  long long x;
  scanf("%I64d", &x);
  return x;
}
double getDouble() {
  double x;
  scanf("%lf", &x);
  return x;
}
char getChar() {
  char x;
  scanf("%c", &x);
  return x;
}
template <typename t>
t abs(t a) {
  if (a >= 0) return a;
  return -a;
}
vector<string> split(const string& s, char c) {
  vector<string> v;
  stringstream second(s);
  string x;
  while (getline(second, x, c)) v.emplace_back(x);
  return move(v);
}
void err(vector<string>::iterator it) {}
template <typename T, typename... Args>
void err(vector<string>::iterator it, T a, Args... args) {
  cout << it->substr((*it)[0] == ' ', it->length()) << " = " << a << "  ";
  err(++it, args...);
}
void FastIO() {
  ios::sync_with_stdio(0);
  cin.tie(0);
}
int a[25][25];
int b[25][25];
int n, m;
inline void copyar() {
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= m; j++) b[i][j] = a[i][j];
}
inline void swapcol(int x, int y) {
  for (int i = 1; i <= n; i++) swap(b[i][x], b[i][y]);
}
inline bool possible() {
  for (int i = 1; i <= n; i++) {
    int swaps = 0;
    for (int j = 1; j <= m; j++) {
      if (b[i][j] != j) {
        swap(b[i][j], b[i][b[i][j]]);
        swaps++;
      }
    }
    if (swaps > 1) return 0;
  }
  return 1;
}
int main() {
  cin >> n >> m;
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= m; j++) cin >> a[i][j];
  copyar();
  if (possible()) {
    puts("YES");
    return 0;
  }
  for (int x = 1; x <= m; x++)
    for (int y = x + 1; y <= m; y++) {
      copyar();
      swapcol(x, y);
      if (possible()) {
        puts("YES");
        return 0;
      }
    }
  puts("NO");
  return 0;
}
