#include<bits/stdc++.h>
#define SOR(vec) sort((vec).begin(),(vec).end())
using namespace std;
int n,m,pa1[12],pa2[12];
string grid[12],sorg[12];
bool ac(int id1,int id2){
	for(int it=0;it<n;it++) if(grid[it][id1]!=grid[pa1[it]][id2]) return false;
	return true;
}
void dfs1(int cur,int rem){
	if(cur==m) cout<<"YES"<<endl,exit(0);
	else if(pa2[cur]!=-1) dfs1(cur+1,rem);
	else{
		for(int nxt=cur+1;nxt<m;nxt++)
			if(pa2[nxt]==-1&&ac(cur,nxt))
				pa2[nxt]=cur,pa2[cur]=nxt,dfs1(cur+1,rem),pa2[nxt]=pa2[cur]=-1;
		if(rem) pa2[cur]=cur,dfs1(cur+1,0),pa2[cur]=-1;
	}
}
void dfs2(int cur,int rem){
	if(cur==n) dfs1(0,(m%2));
	else if(pa1[cur]!=-1) dfs2(cur+1,rem);
	else{
		for(int nxt=cur+1;nxt<n;nxt++)
			if(pa1[nxt]==-1&&sorg[cur]==sorg[nxt])
				pa1[nxt]=cur,pa1[cur]=nxt,dfs2(cur+1,rem),pa1[nxt]=pa1[cur]=-1;
		if(rem) pa1[cur]=cur,dfs2(cur+1,0),pa1[cur]=-1;
	}
}
int main(){
	ios::sync_with_stdio(0);
	cin.tie(NULL);
	cout.tie(NULL);
	cin>>n>>m;
	memset(pa1,-1,sizeof(pa1));
	memset(pa2,-1,sizeof(pa2));
	for(int i=0;i<n;i++) cin>>grid[i];
	for(int i=0;i<n;i++) sorg[i]=grid[i],SOR(sorg[i]);
	dfs2(0,(n%2));
	cout<<"NO"<<endl;
	return 0;
}
