//testing
#include <bits/stdc++.h>
using namespace std;
 
const long long int MOD = 1000000007;
 
long long int N, M, K, H, W, L, R;
 
int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
 
	cin >> H >> W;
	vector<string>r(H);
	vector<string>c(W);
	for (int i = 0; i < H; i++) {
		cin >> r[i];
	}
	for (int i = 0; i < H; i++) {
		for (int j = 0; j < W; j++) {
			c[j].push_back(r[i][j]);
		}
	}
	for (int i = 0; i < H; i++) {
		sort(r[i].begin(), r[i].end());
	}
	for (int i = 0; i < W; i++) {
		sort(c[i].begin(), c[i].end());
	}
 
	int rood = 0;
	vector<int>ro(13);
	for (int i = 0; i < H; i++) {
		int cnt = 0;
		for (int j = 0; j < H; j++) {
			if (r[i] == r[j]) {
				cnt++;
			}
		}
		ro[cnt]++;
	}
	int cood = 0;
	vector<int>co(13);
	for (int i = 0; i < W; i++) {
		int cnt = 0;
		for (int j = 0; j < W; j++) {
			if (c[i] == c[j]) {
				cnt++;
			}
		}
		co[cnt]++;
	}
	for (int i = 1; i <= 11; i += 2) {
		rood += ro[i] / i;
	}
	for (int i = 1; i <= 11; i += 2) {
		cood += co[i] / i;
	}
	if ((H & 1) < rood || (W & 1) < cood) {
		cout << "NO\n";
		return 0;
	}
	if ((!(H & 1) && rood) || (!(W & 1) && cood)) {
		cout << "NO\n";
		return 0;
	}
	if (H >= 7 && H < 9 && W >= 7 && W < 9 && ro[H] && co[W]) {
		cout << "NO\n";
		return 0;
	}
	cout << "YES\n";
	return 0;
}
