func_code_string: #include <bits/stdc++.h>   using namespace std;   const int N = 25, INF = 1e9 + 5;   inline int read() {     char c = getchar();     int x = 0, f = 1;     while (c <  0  || c >  9 ) {       if (c ==  - ) f = -1;       c = getchar();     }     while (c >=  0  && c <=  9 ) {       x = x * 10 + c -  0 ;       c = getchar();     }     return x * f;   }   int n, m, a[N][N];   bool check() {     for (int i = 1; i <= n; i++) {       int cnt = 0;       for (int j = 1; j <= m; j++)         if (a[i][j] != j) cnt++;       if (cnt > 2) return false;     }     return true;   }   int main() {     n = read();     m = read();     for (int i = 1; i <= n; i++)       for (int j = 1; j <= m; j++) a[i][j] = read();     if (check()) {       puts( YES );       return 0;     }     for (int i = 1; i <= m; i++)       for (int j = i + 1; j <= m; j++) {         for (int z = 1; z <= n; z++) swap(a[z][i], a[z][j]);         if (check()) {           puts( YES );           return 0;         }         for (int z = 1; z <= n; z++) swap(a[z][i], a[z][j]);       }     puts( NO );   }   