Problem:
Score : 700 points

Problem Statement

There is an H \times W grid (H vertical, W horizontal), where each square contains a lowercase English letter.
Specifically, the letter in the square at the i-th row and j-th column is equal to the j-th character in the string S_i.

Snuke can apply the following operation to this grid any number of times:

Choose two different rows and swap them. Or, choose two different columns and swap them.

Snuke wants this grid to be symmetric.
That is, for any 1 \leq i \leq H and 1 \leq j \leq W, the letter in the square at the i-th row and j-th column and the letter in the square at the (H + 1 - i)-th row and (W + 1 - j)-th column should be equal.

Determine if Snuke can achieve this objective.

Constraints

1 \leq H \leq 12

1 \leq W \leq 12

|S_i| = W

S_i consists of lowercase English letters.

Input

Input is given from Standard Input in the following format:

H W
S_1
S_2
:
S_H

Output

If Snuke can make the grid symmetric, print YES; if he cannot, print NO.

Sample Input 1

2 3
arc
rac

Sample Output 1

YES

If the second and third columns from the left are swapped, the grid becomes symmetric, as shown in the image below:

Sample Input 2

3 7
atcoder
regular
contest

Sample Output 2

NO

Sample Input 3

12 12
bimonigaloaf
faurwlkbleht
dexwimqxzxbb
lxdgyoifcxid
ydxiliocfdgx
nfoabgilamoi
ibxbdqmzxxwe
pqirylfrcrnf
wtehfkllbura
yfrnpflcrirq
wvcclwgiubrk
lkbrwgwuiccv

Sample Output 3

YES

Solution in C++14 (GCC 5.4.1) (judge verdict: Wrong Answer)

#include <stdio.h>  
#include <algorithm>  
#include <assert.h>
#include <bitset>
#include <cmath>  
#include <complex>  
#include <deque>  
#include <functional>  
#include <iostream>  
#include <limits.h>  
#include <map>  
#include <math.h>  
#include <queue>  
#include <set>  
#include <stdlib.h>  
#include <string.h>  
#include <string>  
#include <time.h>  
#include <unordered_map>  
#include <unordered_set>  
#include <vector>  

#pragma warning(disable:4996)  
#pragma comment(linker, "/STACK:336777216")  
using namespace std;

#define mp make_pair  
#define Fi first  
#define Se second  
#define pb(x) push_back(x)  
#define szz(x) ((int)(x).size())  
#define rep(i, n) for(int i=0;i<n;i++)  
#define all(x) (x).begin(), (x).end()  
#define ldb ldouble  

typedef unsigned int uint;
typedef tuple<int, int, int> t3;
typedef long long ll;
typedef unsigned long long ull;
typedef double db;
typedef long double ldb;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;
typedef pair <ll, int> pli;
typedef pair <db, db> pdd;

int IT_MAX = 1 << 19;
const ll MOD = 1000000007;
const int INF = 0x3f3f3f3f;
const ll LL_INF = 0x3f3f3f3f3f3f3f3f;
const db PI = acos(-1);
const db ERR = 1e-10;

int X[12];

char D[12][13];
int N, M;
int ans = 0;

void solve(){
//	for(int i = 0; i < M; i++) printf("%d ", X[i]); printf("\n");
	int dp[1<<12] = {};
	int pos[12][12] = {};
	for(int i = 0; i < N; i++){
		for(int j = 0; j < N; j++){
			pos[i][j] = 1;
			for(int k = 0; k < M; k++){
				if(D[i][k] != D[j][X[k]]) pos[i][j] = 0;
			}
//			printf("%d ", pos[i][j]);
		}
//		printf("\n");
	}
	dp[0] = 1;
	for(int i = 0; i+1 < 1<<N; i++){
		if(dp[i] == 0) continue;
		int v = 0;
		for(v = 0; i&1<<v; v++);
		for(int u = 0; u < N; u++){
			if(u == v || (1<<u&i) || !pos[u][v]) continue;
			dp[1<<u | 1<<v | i] = 1;
		}
	}
	int mx = (1<<N) - 1;
	if(N%2 == 1){
		for(int i = 0; i < N; i++){
			if(pos[i][i] && dp[mx^1<<i]) ans = 1;
		}
	}
	else{
		if(dp[mx]) ans = 1;
	}
}

void dfs(int x, int ch){
	if(x == M) return solve();
	if(X[x] != -1){
		dfs(x+1, ch);
		return;
	}
	if(ch){ X[x] = x; dfs(x+1, 0); X[x] = -1; }
	for(int i = x+1; i < M; i++){
		if(X[i] != -1) continue;
		X[x] = i; X[i] = x;
		dfs(x+1, ch);
		X[x] = X[i] = -1;
	}
}

int main()
{
	scanf("%d%d", &N, &M);
	for(int i = 0; i < N; i++) scanf("%s", D[i]);
	for(int i = 0; i < M; i++) X[i] = -1;
	dfs(0, M%2);
	printf("%s\n", ans?"YES":"NO");
}