#include<bits/stdc++.h>
#define fo(i,a,b) for((i)=(a);i<=(b);i++)
#define rfo(i,a,b) for((i)=(a);i>=(b);i--)
#define inrange(x,y,z) (((x)>=(y))&&((x)<=(z)))
#define ALL(vec) ((vec).begin(),(vec).end())
#define SOR(vec) sort(ALL(vec))
#define UNI(vec) (vec).erase(unique(ALL(vec)),(vec).end())
using namespace std;
int n,m,pa[12],pb[12];
string a[12],b[12];
void dfs1(int x,bool free){
	if(x==m) cout<<"YES"<<endl,exit(0);
	else if(pb[x]!=-1) dfs1(x+1,free);
	else{
		for(int y=x+1;y<m;y++){
			if(pb[y]!=-1) continue;
			int ok=1;
			for(int z=0;z<n;z++) if(a[z][x]!=a[pa[z]][y]){ok=0;break;}
			if(ok) pb[x]=y,pb[y]=x,dfs1(x+1,free),pb[x]=pb[y]=-1;
		}
		if(free){
			int ok=1;
			for(int z=0;z<n;z++) if(a[z][x]!=a[pa[z]][x]){ok=0;break;}
			if(ok) pb[x]=x,dfs1(x+1,0),pb[x]=-1;
		}
	}
}
void dfs2(int x,bool free){
	if(x==n) dfs1(0,m%2);
	else if(pa[x]!=-1) dfs2(x+1,free);
	else{
		for(int y=x+1;y<n;y++) if(pa[y]==-1&&b[x]==b[y])
			pa[x]=y,pa[y]=x,dfs2(x+1,free),pa[x]=pa[y]=-1;
		if(free)
			pa[x]=x,dfs2(x+1,0),pa[x]=-1;
	}
}
int main(){
	#ifdef FILIN
		#ifndef DavidDesktop
			freopen(FILIN,"r",stdin);
			freopen(FILOUT,"w",stdout);
		#endif
	#endif
	ios::sync_with_stdio(0);
	cin.tie(NULL);
	cout.tie(NULL);
	cin>>n>>m;
	for(int i=0;i<n;i++) cin>>a[i];
	for(int i=0;i<n;i++)
		b[i]=a[i],sort(b[i].begin(),b[i].end());
	memset(pa,-1,sizeof(pa));
	memset(pb,-1,sizeof(pb));
	dfs2(0,n%2);
	cout<<"NO"<<endl;
	return 0;
}
