#include <bits/stdc++.h>

using namespace std;

typedef pair <int, int> pii;

vector < pii > v;
string S[15];
int n, m;
bool ans = false;

bool check(){
	for(auto f : v){
		S[f.first].swap(S[f.second]);
	}
	map <string, int> mp;
	string a, b;
	for(int i = 0; i < m; ++i){
		a = "";
		for(int j = 0; j < n; ++j){
			a += S[j][i];
		}
		mp[a] += 1;
	}
	int res = true;
	int cnt = 0;
	for(auto u : mp){
		b = u.first;
		reverse(b.begin(), b.end());
		if(b == u.first){
			if(u.second % 2) cnt += 1;
			if(cnt > 1){
				res = false;
				break;
			}
		}
		else{
			if(u.second != mp[b]){
				res = false;
				break;
			}
		}
	}
	res &= (cnt < 2);
	for(auto f : v){
		S[f.first].swap(S[f.second]);
	}
	return res;
}

void fn(int mask){
	if(ans) return;
	int sz = __builtin_popcount(mask);
	if(sz <= 1){
		ans |= check();
		return;
	}
	int k;
	for(int i = n - 1; i >= 0; --i){
		if(mask & (1 << i)){
			mask ^= (1 << i);
			fn(mask);
			for(int j = 0; j < i; ++j){
				if(mask & (1 << j)){
					v.push_back({i, j});
					fn(mask ^ (1 << j));
					v.pop_back();
				}
			}
			break;
		}
	}
}

int main(){
	cin >> n >> m;
	int mask = 0;
	for(int i = 0; i < n; ++i){
		cin >> S[i];
		mask |= (1 << i);
	}
	fn(mask);
	if(ans) cout << "YES\n";
	else cout << "NO\n";
}
