import std.stdio, std.algorithm, std.range, std.conv, std.string, std.math;
import core.stdc.stdio;
// foreach, foreach_reverse, writeln

void main() {
	int h, w;
	scanf("%d%d\n", &h, &w);
	string[] s = new string[h];
	foreach (i; 0..h) {
		s[i] = chomp(readln());
	}

	int[] p = new int[w];
	bool[] used = new bool[w];
	bool dfs(int i) {
		if (i == w) {
			char[][] s1 = new char[][](h,w);
			foreach (j; 0..h) {
				foreach (k; 0..w) {
					s1[j][k] = s[j][p[k]];
				}
			}
			char[][] s2 = new char[][](h,w);
			foreach (j; 0..h) {
				foreach (k; 0..w) {
					s2[j][k] = s1[j][w-1-k];
				}
			}
			s1.sort; s2.sort;
			return s1 == s2;
		}
		foreach (j; 0..w) {
			if (used[j]) continue;
			used[j] = true;
			p[i] = j;
			if (dfs(i+1)) return true;
			used[j] = false;
			if (i >= (w+1)/2) break;
		}
		return false;
	}
	writeln(dfs(0) ? "YES" : "NO");
}