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

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

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

    auto bant = new dchar[][](w, h);
    foreach (i ; 0 .. h) {
        foreach (j ; 0 .. w) {
            bant[j][i] = ban[i][j];
        }
    }

    debug {
        writefln("%-(%s\n%)", ban);
        writefln("%-(%s\n%)", bant);
    }

    auto ans = check(ban) && check(bant);

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

bool check(dchar[][] ban) {
    auto a = new dchar[][](0, 0);

    foreach (si ; ban) {
        a ~= si.sort().to!(dchar[]);
    }

    a.sort();

    debug {
        writeln(a);
    }

    auto b = a.group.filter!"a[1] % 2 != 0".map!"a[0]".array;

    debug {
        writeln(b);
    }

    if (b.length > 1) {
        return 0;
    }

    if (b.length == 0) {
        return 1;
    }

    auto s = b.front;

    if (!kaibun(s)) {
        return 0;
    }

    return 1;
}

bool kaibun(dchar[] s) {
    return s.sort().group.filter!"a[1] % 2 == 1".count <= 1;
}

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);
        }
    }
}
