#include <bits/stdc++.h>
#define ll long long
#define ull unsigned long long
#define MP make_pair
#define PII pair<int, int>
#define PLL pair<ll, ll>
#define PLI pair<ll, int>
#define PIL pair<int, ll>
#define STR string
#define Fst first
#define Snd second
#define SHN 1e9
#define LSHN 1e18
using namespace std;
int n,m;
string s[20],si[20];
int r[20];
bool visr[20],visc[20];
void dfsc(int x,bool fl)
{
	if (x==m)
	{
		cout <<"YES";
		exit(0);
	}
	if (visc[x])
	{
		dfsc(x+1,fl);
		return;
	}
	visc[x]=1;
	for (int i=0;i<m;i++)
	{
		if (visc[i]) continue;
		bool jum=0;
		for (int j=0;j<n;j++) if (s[j][x]!=s[r[j]][i]) jum=1;
		if (jum) continue;
		visc[i]=1;
		dfsc(x+1,fl);
		visc[i]=0;
	}
	if (fl)
	{
		bool jum=0;
		for (int j=0;j<n;j++) if (s[j][x]!=s[r[j]][x]) jum=1;
		if (!jum) dfsc(x+1,0);
	}
	visc[x]=0;
}
void dfsr(int x,bool fl)
{
	if (x==n)
	{
		dfsc(0,m%2!=0);
		return;
	}
	if (visr[x])
	{
		dfsr(x+1,fl);
		return;
	}
	visr[x]=1;
	for (int i=0;i<n;i++)
	{
		if (visr[i] || si[x]!=si[i]) continue;
		r[x]=i,r[i]=x;
		visr[i]=1;
		dfsr(x+1,fl);
		visr[i]=0;
	}
	if (fl)
	{
		r[x]=x;
		dfsr(x+1,0);
	}
	visr[x]=0;
}
int main()
{
	cin >>n>>m;
	for (int i=0;i<n;i++)
	{
		cin >>s[i];
		si[i]=s[i];
		sort(si[i].begin(),si[i].end());
	}
	dfsr(0,n%2!=0);
	cout <<"NO";
	return 0;
} 