// #includes {{{
#include <bits/stdc++.h>
using namespace std;

#define REP(i,n) for(int i=0;i<(int)(n);++i)
#define RREP(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define FOR(i,c) for(__typeof((c).begin()) i=(c).begin();i!=(c).end();++i)
#define LET(x,a) __typeof(a) x(a)
//#define IFOR(i,it,c) for(__typeof((c).begin())it=(c).begin();it!=(c).end();++it,++i)
#define ALL(c) (c).begin(), (c).end()
#define MP make_pair

#define EXIST(e,s) ((s).find(e)!=(s).end())

#define RESET(a) memset((a),0,sizeof(a))
#define SET(a) memset((a),-1,sizeof(a))
#define PB push_back
#define DEC(it,command) __typeof(command) it=command

//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
#define debug_v(x) cerr << #x << " = [";REP(__ind,(x).size()){cerr << (x)[__ind] << ", ";}cerr << "] (L" << __LINE__ << ")" << endl;

#define whole(f,x,...) ([&](decltype((x)) whole) { return (f)(begin(whole), end(whole), ## __VA_ARGS__); })(x)

typedef long long Int;
typedef unsigned long long uInt;
typedef long double rn;

template<class T>
T inf(){
	return numeric_limits<T>::has_infinity?numeric_limits<T>::infinity():(numeric_limits<T>::max()/2);
}

typedef pair<int,int> pii;

/*
#ifdef MYDEBUG
#include"debug.h"
#include"print.h"
#endif
*/
// }}}


//{{{ io
FILE *file_in=stdin,*file_out=stdout;
#define fin normal_in
#define fout normal_out
//const char fname[]="";
//FILE *fin=fopen(fname,"r"),*fout=fopen(fname,"w");
#ifdef __MINGW32__
#define LLD "%I64d"
#define LLU "%I64u"
#else
#define LLD "%lld"
#define LLU "%llu"
#endif
struct NORMAL_IN{
	bool cnt;
	NORMAL_IN():cnt(true){}
	operator int() const {return cnt;}
#define endl "\n"
	NORMAL_IN& operator>>(int &n){cnt=fscanf(file_in,"%d",&n)!=EOF;return *this;}
	NORMAL_IN& operator>>(unsigned int &n){cnt=fscanf(file_in,"%u",&n)!=EOF;return *this;}
	NORMAL_IN& operator>>(long long &n){cnt=fscanf(file_in,LLD,&n)!=EOF;return *this;}
	NORMAL_IN& operator>>(unsigned long long &n){cnt=fscanf(file_in,LLU,&n)!=EOF;return *this;}
	NORMAL_IN& operator>>(double &n){cnt=fscanf(file_in,"%lf",&n)!=EOF;return *this;}
	NORMAL_IN& operator>>(long double &n){cnt=fscanf(file_in,"%Lf",&n)!=EOF;return *this;}
	NORMAL_IN& operator>>(char *c){cnt=fscanf(file_in,"%s",c)!=EOF;return *this;}
	NORMAL_IN& operator>>(string &s){
		s.clear();
		for(bool r=false;;){
			const char c=getchar();
			if(c==EOF){ cnt=false; break;}
			const int t=isspace(c);
			if(!r and !t)r=true;
			if(r){
				if(!t)s.push_back(c);
				else break;
			}
		}
		return *this;
	}
	template<class T>
		NORMAL_IN& operator>>(vector<T> &v){
			int n;fscanf(file_in,"%d",&n);
			REP(i,n){
				T t;*this>>t;
				v.push_back(t);
			}
			return *this;
		}
} normal_in;

struct NORMAL_OUT{
	NORMAL_OUT& operator<<(const int &n){fprintf(file_out,"%d",n);return *this;}
	NORMAL_OUT& operator<<(const unsigned int &n){fprintf(file_out,"%u",n);return *this;}
	NORMAL_OUT& operator<<(const long long &n){fprintf(file_out,LLD,n);return *this;}
	NORMAL_OUT& operator<<(const unsigned long long &n){fprintf(file_out,LLU,n);return *this;}
	NORMAL_OUT& operator<<(const double &n){fprintf(file_out,"%lf",n);return *this;}
	NORMAL_OUT& operator<<(const long double &n){fprintf(file_out,"%Lf",n);return *this;}
	NORMAL_OUT& operator<<(const char c[]){fprintf(file_out,"%s",c);return *this;}
	NORMAL_OUT& operator<<(const string &s){fprintf(file_out,"%s",s.c_str());return *this;}
} normal_out;
struct ERR_OUT{
	template<class T>
		ERR_OUT& operator<<(const T &a){
			cerr<<"\x1b[7m"<<a<<"\x1b[m";
			return *this;
		}
} ferr;
//}}}

int H,W;
vector<string> S;
vector<bool> row_selected, col_selected;
int row_center=-1, col_center=-1;
vector<pair<int,int> > row_pair, col_pair;
bool found = false;

bool row_pairable[15][15];

bool col_pairable(int j0, int j1){
	if(row_center!=-1){
		if(S[row_center][j0]!=S[row_center][j1])return false;
	}
	for(auto &&p:row_pair){
		if(S[p.first][j0]!=S[p.second][j1])return false;
		if(S[p.first][j1]!=S[p.second][j0])return false;
	}
	return true;
}

bool col_be_center(int j){
	for(auto &&p:row_pair){
		if(S[p.first][j]!=S[p.second][j])return false;
	}
	return true;
}

void col_rec2(){
	for(int j=0;j<W;j++){
		if(col_selected[j])continue;
		col_selected[j] = true;
		bool col_found = false;
		for(int j1=j+1;j1<W;j1++){
			if(col_selected[j1])continue;
			if(!col_pairable(j,j1))continue;
			col_selected[j1] = true;
			col_found = true;
			break;
		}
		if(!col_found){
			return;
		}
	}
	found = true;
}

void col_rec(){
	if(W%2==1){
		REP(j,W){
			if(!col_be_center(j))continue;
			col_center = j;
			col_selected.assign(W,false);
			col_selected[j] = true;
			col_rec2();
			col_center = -1;
		}
	}else{
		col_selected.assign(W,false);
		col_rec2();
	}
}

void row_rec1(){
	if(found)return;
	int i = 0;
	for(;i<H;i++)if(!row_selected[i])break;
	if(i==H){
		col_rec();
		return;
	}
	row_selected[i] = true;
	for(int i1=i+1;i1<H;i1++){
		if(row_selected[i1] or not row_pairable[i][i1])continue;
		row_selected[i1] = true;
		row_pair.push_back({i,i1});
		row_rec1();
		row_pair.pop_back();
		row_selected[i1] = false;
	}
	row_selected[i] = false;
}

void row_rec(){
	if(H%2==1){
		REP(i,H){
			row_center = i;
			row_selected[i] = true;
			row_rec1();
			row_selected[i] = false;
			row_center = -1;
		}
	}else{
		row_rec1();
	}
}

//{{{ main function
int main(){	
	fin >> H;
	S.assign(H,string());
	fin >> W;
	for(int i = 0 ; i <= H-1 ; i++){
		fin >> S[i];
	}
	REP(i0,H)REP(i1,H){
		string S0(S[i0]), S1(S[i1]);
		sort(ALL(S0));sort(ALL(S1));
		if(S0==S1)row_pairable[i0][i1] = true;
		else row_pairable[i0][i1] = false;
	}
	row_selected.assign(H,false);
	row_rec();
	if(found){
		fout<<"YES"<<endl;
	}else{
		fout<<"NO"<<endl;
	}
	return 0;
}
//}}}


Measured memory_bytes: 256