#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];
bool forb[20][20][20][20];
bool ok[2][5000],bad[20][20];
vector<PII> v;
bool dfs(int x,int y,bool fl)
{
	if (x & (1<<y)) return dfs(x,y+1,fl);
	if (x==(1<<n)-1)
	{
		memset(ok,0,sizeof(ok));
		memset(bad,0,sizeof(bad));
		for (int i=0;i<m;i++)
			for (int j=0;j<m;j++)
				for (int k=0;k<v.size();k++)
					bad[i][j]|=forb[v[k].Fst][v[k].Snd][i][j]; 
		ok[0][0]=1;
		for (int i=0;i<(1<<m)-1;i++)
		{
			for (int j=0;j<m;j++)
			{
				if (i & (1<<j)) continue;
				for (int k=j;k<m;k++)
				{
					if ((i & (1<<k)) || (m%2==0 && j==k) || bad[j][k]) continue;
					if (j!=k)
					{
						ok[0][i|(1<<j)|(1<<k)]|=ok[0][i];
						if (m%2!=0) ok[1][i|(1<<j)|(1<<k)]|=ok[1][i];
					}
					else ok[1][i|(1<<j)]|=ok[0][i];
				}
				break;
			}
		}
		return ok[m%2!=0][(1<<m)-1];
	}
	for (int i=y;i<n;i++)
	{
		if (si[i]!=si[y] || (x & (1<<i)) || (!fl && i==y)) continue;
		v.push_back(MP(i,y));
		if (dfs(x|(1<<i)|(1<<y),y+1,fl&(i!=y))) return 1;
		v.pop_back();
	}
	return 0;
}
int main()
{
	cin >>n>>m;
	for (int i=0;i<n;i++) cin >>s[i];
	for (int i=0;i<n;i++) si[i]=s[i],sort(si[i].begin(),si[i].end());
	for (int i=0;i<n;i++)
		for (int j=0;j<n;j++)
			for (int x=0;x<m;x++)
				for (int y=0;y<m;y++)
					if (s[i][x]!=s[j][y] || s[i][y]!=s[j][x])
						forb[i][j][x][y]=1;
	cout <<(dfs(0,0,n%2!=0) ? "YES" : "NO");
	return 0;
} 