import std.stdio, std.array, std.string, std.conv, std.algorithm;
import std.typecons, std.range, std.random, std.math, std.container;
import std.numeric, std.bigint, core.bitop, std.bitmanip;

void main() {
    auto s = readln.split.map!(to!int);
    auto H = s[0];
    auto W = s[1];
    auto A = H.iota.map!(_ => readln.chomp.map!(a => (a - 'a').to!int).array).array;
    auto B = new int[][](W, H);
    foreach (i; 0..H) foreach (j; 0..W) B[j][i] = A[i][j];

    bool[int][] make_pairs(int[][] C) {
        auto pairs = new bool[int][](C.length);
        foreach (i; 0..C.length) {
            foreach (j; i+1..C.length) {
                bool ok = true;
                auto cnt = new int[][](26, 26);
                foreach (k; 0..C[i].length) {
                    cnt[C[i][k]][C[j][k]] += 1;
                }
                foreach (x; 0..26) {
                    foreach (y; 0..26) {
                        if (cnt[x][y] != cnt[y][x]) {
                            ok = false;
                            break;
                        }
                    }
                    if (!ok) break;
                }
                if (ok) {
                    pairs[i][j.to!int] = true;
                    pairs[j][i.to!int] = true;
                }
            }
        }
        return pairs;
    }


    auto row_pairs = make_pairs(A);
    auto col_pairs = make_pairs(B);

    auto used = new bool[](max(H, W));

    bool dfs(int n, int rc, bool[int][] pairs)  {
        if (used.sum >= rc - rc % 2) return true;
        if (used[n]) return dfs(n+1, rc, pairs);
        foreach (i; 0..rc) {
            if (used[i]) continue;
            used[i] = true;
            foreach (j; pairs[i].keys) {
                if (used[j]) continue;
                used[j] = true;
                if (dfs(n+1, rc, pairs)) return true;
                used[j] = false;
            }
            used[i] = false;
        }
        return false;
    }

    bool aaa = dfs(0, H, row_pairs);
    used.fill(false);
    bool bbb = dfs(0, W, col_pairs);
    writeln(aaa && bbb ? "YES" : "NO");
}
