import std.stdio, std.string, std.conv;
import std.range, std.algorithm, std.array, std.math;

int[] p;
dchar[][] ban;
bool ok;
int h, w;

void main() {
    //int h, w;
    scan(h, w);

    ban = new dchar[][](h, w);
    iota(h).each!(i => ban[i] = readln.chomp.to!(dchar[]));

    p = new int[](h);
    p[] = -1;

    if (h & 1) {
        foreach (i ; 0 .. h) {
            p[i] = h / 2;
            dfs(h, 0);
            p[i] = -1;
        }
    }
    else {
        dfs(h, 0);
    }

    debug {
        writeln(cnt);
    }

    writeln(ok ? "YES" : "NO");
}

int cnt;
int num;

void dfs(int h, int i) {
    if (i == h) {
        debug {
            //writeln(p);
            cnt++;
        }
        solve();
        return;
    }

    if (p[i] != -1) {
        dfs(h, i + 1);
    }
    else {
        foreach (j ; 0 .. h) {
            if (j == i) continue;
            if (p[j] == -1) {
                p[i] = num;
                p[j] = h - 1 - num;
                num++;
                dfs(h, i + 1);
                num--;
                p[i] = p[j] = -1;
            }
        }
    }
}

void solve() {
    auto bb = new dchar[][](h, w);
    foreach (i ; 0 .. h) {
        bb[p[i]] = ban[i].dup;
    }

    debug {
        //writeln(bb);
    }

    auto bt = new dchar[][](w, 0);

    foreach (j;  0 .. w) {
        foreach (i ; 0 .. h) {
            bt[j] ~= bb[i][j];
        }
    }

    debug {
        //writeln(bt);
    }

    auto u = new bool[](w);

    foreach (i ; 0 .. w) {
        if (u[i]) continue;

        foreach (j ; i + 1 .. w) {
            if (equal(bt[i], bt[j].retro)) {
                u[i] = u[j] = 1;
                break;
            }
        }
    }

    int ucnt = u.count!"!a";

    if (ucnt > 1) {
        return;
    }

    if (ucnt == 0) {
        ok = 1;
        return;
    }

    debug {
        writeln(u.countUntil!"!a");
    }

    auto s = bt[u.countUntil!"!a"];

    if (equal(s, s.retro)) {
        ok = 1;
    }

    return;
}



void scan(T...)(ref T args) {
    import std.stdio : readln;
    import std.algorithm : splitter;
    import std.conv : to;
    import std.range.primitives;

    auto line = readln().splitter();
    foreach (ref arg; args) {
        arg = line.front.to!(typeof(arg));
        line.popFront();
    }
    assert(line.empty);
}



void fillAll(R, T)(ref R arr, T value) {
    static if (is(typeof(arr[] = value))) {
        arr[] = value;
    }
    else {
        foreach (ref e; arr) {
            fillAll(e, value);
        }
    }
}
