#include <bits/stdc++.h>
using namespace std;
int a[25][25], b[25];
int n, m;
int cur[25], req[25];
bool can(int x, int y) {
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < m; ++j) {
      cur[j] = a[i][j];
    }
    swap(cur[x], cur[y]);
    int c = 0;
    for (int j = 0; j < m; ++j) {
      if (cur[j] != j) {
        c++;
      }
    }
    if (c <= 2) {
      continue;
    }
    swap(cur[x], cur[y]);
    c = 0;
    for (int j = 0; j < m; ++j) {
      if (j == x) {
        if (cur[j] != y) {
          c++;
        }
      } else if (j == y) {
        if (cur[j] != x) {
          c++;
        }
      } else {
        if (cur[j] != j) {
          c++;
        }
      }
    }
    if (c > 2) {
      return false;
    }
  }
  return true;
}
int main() {
  cin >> n >> m;
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < m; ++j) {
      cin >> a[i][j];
      a[i][j]--;
    }
  }
  bool ok = can(0, 0);
  for (int i = 0; i < m; ++i) {
    for (int j = i + 1; j < m; ++j) {
      ok |= can(i, j);
    }
  }
  cout << (ok ? "YES\n" : "NO\n");
  return 0;
}
