#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define sqr(x) ((x)*(x))
#define mp make_pair
#define uint unsigned
inline char gc(){
    static char buf[100000],*p1=buf,*p2=buf;
    return p1==p2&&(p2=(p1=buf)+fread(buf,1,100000,stdin),p1==p2)?EOF:*p1++;
}
#define gc getchar
inline int read(){
	int x = 0; char ch = gc(); bool positive = 1;
	for (; !isdigit(ch); ch = gc())	if (ch == '-')	positive = 0;
	for (; isdigit(ch); ch = gc())	x = x * 10 + ch - '0';
	return positive ? x : -x;
}
inline void write(int a){
    if(a>=10)write(a/10);
    putchar('0'+a%10);
}
inline void writeln(int a){
    if(a<0){
    	a=-a; putchar('-');
	}
	write(a); puts("");
}
const int N=15;
char ch[N][N];
int n,m,v[N],vis[N];
bool sam(int a,int b){
	for(int i=1;i<=n;i++)if(ch[i][a]!=ch[n-i+1][b])return 0;
	return 1;
}
void check(){
	int fff=0; memset(v,0,sizeof(v));
	for(int i=1;i<=m;i++)if(!v[i]){
		int flag=0;
		for(int j=i+1;j<=m;j++)if(!v[j]&&sam(i,j)){
			v[j]=1; flag=1; break;
		}
		if(!flag&&(m%2==0))return;
		else if(!flag&&fff)return;
		else if(!flag&&!sam(i,i))return;
		else if(!flag)fff=1;
	}
	puts("YES"); exit(0);
}
void dfs(int p){
	if(p>n){
		check(); return;
	}
	if(vis[p]){
		dfs(p+1); return;
	}
	for(int i=p;i<=n;i++)if(!vis[i]){
		vis[i]=1; swap(ch[p],ch[i]); dfs(p+1); swap(ch[p],ch[i]); vis[i]=0;
	}
}
int main(){
	n=read(); m=read();
	for(int i=1;i<=n;i++){
		scanf("%s",ch[i]+1);
	}
	dfs(1);
	puts("NO");
}
