#include <iostream>
#include <string>
#include <cmath>
#include<algorithm>
#include<stack>
#include<queue>
#include<map>
#include<set>
#include<iomanip>
#define _USE_MATH_DEFINES
#include <math.h>
#include <functional>
#include<complex>
using namespace std;

#define rep(i,x) for(ll i=0;i<x;i++)
#define repn(i,x) for(ll i=1;i<=x;i++)

typedef long long ll;
const ll INF = 1e17;
const ll MOD = 1000000007;
const ll MAX = 4000001;
const double eps = 1E-18;

ll max(ll a, ll b) {
	if (a > b) { return a; }
	return b;
}

ll min(ll a, ll b) {
	if (a > b) { return b; }
	return a;
}

ll gcd(ll a, ll b) {
	if (b == 0) { return a; }
	if (a < b) { return gcd(b, a); }
	return gcd(b, a % b);
}

ll lcm(ll a, ll b) {
	return a / gcd(a, b) * b;
}

struct edge {
	ll ind;
	ll fr;
	ll to;
	ll d;
};

class mint {
	long long x;
public:
	mint(long long x = 0) : x((x% MOD + MOD) % MOD) {}
	mint operator-() const {
		return mint(-x);
	}
	mint& operator+=(const mint& a) {
		if ((x += a.x) >= MOD) x -= MOD;
		return *this;
	}
	mint& operator-=(const mint& a) {
		if ((x += MOD - a.x) >= MOD) x -= MOD;
		return *this;
	}
	mint& operator*=(const  mint& a) {
		(x *= a.x) %= MOD;
		return *this;
	}
	mint operator+(const mint& a) const {
		mint res(*this);
		return res += a;
	}
	mint operator-(const mint& a) const {
		mint res(*this);
		return res -= a;
	}
	mint operator*(const mint& a) const {
		mint res(*this);
		return res *= a;
	}

	mint operator^(const ll& t)const {
		if (!t) return 1;
		mint a = pow(t >> 1);
		a *= a;
		if (t & 1) a *= *this;
		return a;
	}

	mint pow(ll t) const {
		if (!t) return 1;
		mint a = pow(t >> 1);
		a *= a;
		if (t & 1) a *= *this;
		return a;
	}
	// for prime MOD
	mint inv() const {
		return pow(MOD - 2);
	}
	mint& operator/=(const mint& a) {
		return (*this) *= a.inv();
	}
	mint operator/(const mint& a) const {
		mint res(*this);
		return res /= a;
	}

	friend ostream& operator<<(ostream& os, const mint& m) {
		os << m.x;
		return os;
	}
};

///////////////////////////

ll H, W;
vector<vector<char>> s;


bool dfs2(ll K, vector<vector<ll>> g, vector<ll> pw, ll ziko) {
	if (K == (W + 1) / 2) {
		repn(i, W) { if (pw[i] == 0) { return false; } }
		return true; }

	ll t;
	repn(i, W) {
		if (pw[i] == 0) { t = i; }
	}

	for (ll u : g[t]) {
		if (pw[u] != 0) { continue; }
		if (u == t && ziko == 1) { continue; }
		pw[u] = t;
		pw[t] = u;
		bool b;

		//cout << K + 1 <<" "<<ziko<< endl;
		//repn(i, W) cout << pw[i] << " ";
		//cout << endl;

		if (u == t) { b = dfs2(K + 1, g, pw, 1); }
		else { b = dfs2(K + 1, g, pw, ziko); }
		
		if (b) { return true; }

		pw[u] = 0;
		pw[t] = 0;
	}

	return false;
}


bool dfs(ll K, vector<ll> ph, ll ziko) {
	if(K==(H+1)/2){

		repn(i, H) if (ph[i] == 0) { return false; }
		
		vector<vector<ll>> g(W + 1);
		repn(i, W)repn(j, W) {
			bool b = 1;
			repn(k, H) { if (s[k][i] != s[ph[k]][j] || s[k][j] != s[ph[k]][i]) { b = 0; break; } }
			if (b) { g[i].push_back(j); }

			//cout << i << j << b << endl;
		}

		vector<ll> pw(W + 1, 0);
		bool b = dfs2(0, g, pw, 0);

		return b;
	}
	
	ll t;
	repn(i, H) {
		if (ph[i] == 0) { t = i; break; }
	}

	for (ll j = t; j <= H; j++) {
		if (ph[j] == 0) {
			if (j == t && ziko == 1) { continue; }

			ph[t] = j;
			ph[j] = t;

			bool b;

			//cout << K + 1 <<endl;
			//repn(i, H) cout << ph[i] << " ";
			//cout << endl;
			
			if (j == t) { b = dfs(K + 1, ph, 1); }
			else { b = dfs(K + 1, ph, ziko); }

			

			if (b) { return true; }

			ph[t] = 0;
			ph[j] = 0;
		}
	}

	return false;
}



int main() {
	cin >> H >> W;
	s.assign(H + 1, vector<char>(W + 1, ','));
	repn(i, H)repn(j, W) cin >> s[i][j];

	vector<ll> ph(H + 1, 0);

	bool b = dfs(0, ph, 0);

	if (b) { cout << "YES" << endl; }
	else { cout << "NO" << endl; }
	
	
	system("PAUSE");
}


Measured memory_bytes: 504