// by Balloons
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
#define mpr make_pair
#define debug() puts("okkkkkkkk")
#define rep(i,a,b) for(int (i)=(a);(i)<=(b);(i)++)

using namespace std;

typedef long long LL;

const int inf = 1e9;
int n,m;
char s[15][15];
char d[15],e[15];
bool dfs2(int x){
	if(x>m)return 1;
	if(e[x])return dfs2(x+1);
	int t=0;
	for(int i=x;i<=m;i++)
		if(!e[i])++t;
	for(int i=x;i<=m;i++){
		if(!e[i]){
			int fg=1;
			e[x]=i,e[i]=x;
			for(int j=1;j<=n;j++){
				if((s[j][x]!=s[d[j]][i]) || (s[d[j]][x]!=s[j][i])){fg=0;break;}
			}
			if(i==x){
				if(fg&&(t&1)&&dfs2(x+1))return 1;
			}
			else{
				if(fg){if(dfs2(x+1))return 1;else return 0;}
			}
			e[x]=0,e[i]=0;
		}
	}
	return 0;
}
bool dfs1(int x){
	if(x>n)return dfs2(1);
	if(d[x])return dfs1(x+1);
	else{
		int t=0;
		for(int i=x;i<=n;i++)if(!d[i])++t;
		for(int i=x;i<=n;i++){
			if(!d[i]){
				d[x]=i,d[i]=x;
				if(((t&1)||(i!=x))&&dfs1(x+1))return 1;
				d[x]=0,d[i]=0;
			}
		}
	}
	return 0;
}

int main(){
	scanf("%d%d",&n,&m);
	for(int i=1;i<=n;i++)scanf("%s",s[i]+1);
	if(dfs1(1))puts("YES");
	else puts("NO");

	return 0;
}
