#include <bits/stdc++.h>

using namespace std;

#define SZ(v) ((int)(v).size())
#define ALL(v) (v).begin(),(v).end()
#define one first
#define two second
typedef long long ll;
typedef pair<int, int> pi;
const int INF = 0x3f2f1f0f;
const ll LINF = 1ll * INF * INF;

const int MAX_N = 20;

int N, M;
bool Vis[MAX_N];
char Mp[MAX_N][MAX_N];
char Now[MAX_N][MAX_N];
string S[MAX_N];
void chooseH() {
	map<string, set<int>> mp;
	vector<bool> vis(N, false);
	for(int i=0; i<N; i++) {
		S[i] = Now[i];
		//printf("%d : %s\n", i, S[i].c_str());
		mp[S[i]].insert(i);
		string rs = S[i]; reverse(ALL(rs));
	}
	puts("");
	bool used = false;
	if(N % 2 == 0) used = true;
	for(int i=0; i<N; i++) if(!vis[i]) {
		vis[i] = true;
		string s = S[i];
		mp[S[i]].erase(i);
		string rs = s;
		reverse(ALL(rs));
		if(SZ(mp[rs]) == 0) {
			if(rs == s) {
				if(used) return;
				used = true;
			}else{
				return;
			}
		}else{
			auto it = mp[rs].begin();
			vis[*it] = true;
			mp[rs].erase(it);
		}
	}
	puts("YES");
	exit(0);
}
void chooseW(int who, int ix, int cnt) {
	if(who == M) return chooseH();
	if(Vis[who]) return chooseW(who+1, ix, cnt);
	Vis[who] = true;
	for(int k=0; k<N; k++) Now[k][ix] = Mp[k][who];
	for(int i=who+1; i<M; i++) if(not Vis[i]) {
		Vis[i] = true;
		for(int k=0; k<N; k++) Now[k][M-1-ix] = Mp[k][i];
		chooseW(who+1, ix+1, cnt+2);
		Vis[i] = false;
	}
	Vis[who] = false;
}
int main() {
	cin >> N >> M;
	for(int i=0; i<N; i++) scanf("%s", Mp[i]);
	for(int k=0; k<N; k++) Now[k][M] = 0;
	if(M % 2 == 1) {
		for(int i=0; i<M; i++) {
			int who = i;
			Vis[who] = true;
			for(int k=0; k<N; k++) Now[k][M/2] = Mp[k][who];
			chooseW(0, 0, 1);
			Vis[who] = false;
		}
	}else chooseW(0, 0, 0);
	puts("NO");
	return 0;
}
