#include <bits/stdc++.h>
using namespace std;
#define DEBUG_MODE
#define endl '\n'
#ifdef DEBUG_MODE
#define DEBUG(...) debug_func_mult(split_names(#__VA_ARGS__), __VA_ARGS__)
#define DEBUG_ENDL endl << flush
#define DEBUG_SEPARATOR_LINE cout<<"=================\n"
#else
#define DEBUG(...) 0
#define DEBUG_ENDL 0
#define DEBUG_SEPARATOR_LINE 0
#endif
#define ALL(V) (V).begin(), (V).end()
#define ALLR(V) (V).rbegin(), (V).rend()
#define DEBUG_ENDL_S(S) ((S).size() ? "\n" : "") << flush;

template <typename T> using V = vector<T>;
template <typename T> using VV = V<V<T>>;
template <typename T, typename U> using P = pair<T, U>;
using ll = int64_t;
using PLL = P<ll, ll>;

template <typename T> const T& var_min(const T &t) { return t; }
template <typename T> const T& var_max(const T &t) { return t; }
template <typename Head, typename... Tail> const Head& var_min(const Head &head, const Tail&... tail) { return min(head, var_min(tail...)); }
template <typename Head, typename... Tail> const Head& var_max(const Head &head, const Tail&... tail) { return max(head, var_max(tail...)); }
template <typename T, typename... Tail> void chmin(T &t, const Tail&... tail) { t = var_min(t, tail...); }
template <typename T, typename... Tail> void chmax(T &t, const Tail&... tail) { t = var_max(t, tail...); }

void debug_func_preffix(const string &s) { if(s.size()) cout << s << " = "; }

template <typename T>
void debug_func(const T &t, const string &s = "") {
    debug_func_preffix(s);
    cout << t << DEBUG_ENDL_S(s);
}

template <typename T, typename U>
void debug_func(const P<T, U> &p, const string &s = "") {
    debug_func_preffix(s);
    cout << "(";
    debug_func(p.first);
    cout << ", ";
    debug_func(p.second);
    cout << ")" << DEBUG_ENDL_S(s);
}

template <typename T>
void debug_func(const V<T> &v, const string &s = "") {
    for(ll i = 0; i < v.size(); i++) {
        string t = s + "[" + to_string(i) + "]";
        debug_func(v[i], t);
    }
}

template <typename T>
void debug_func_mult(int idx, const V<string> &names, const T &t) {
    debug_func(t, names[idx]);
}

template <typename T>
void debug_func_mult(const V<string> &names, const T &t) {
    debug_func(t, names[0]);
}

template <typename Head, typename... Tail>
void debug_func_mult(int idx, const V<string> &names, const Head &head, const Tail&... args) {
    debug_func(head, names[idx]);
    debug_func_mult(idx + 1, names, args...);
}

template <typename Head, typename... Tail>
void debug_func_mult(const V<string> &names, const Head &head, const Tail&... args) {
    debug_func(head, names[0]);
    debug_func_mult(1, names, args...);
}

V<string> split_names(string &&s) {
    replace(ALL(s), ' ', ',');
    V<string> ret;
    istringstream ss(s);
    string t;
    while(getline(ss, t, ',')) if(t.size()) ret.push_back(move(t));
    return move(ret);
}

void init_io() {
    cin.tie(0);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(30);
}

V<string> S;
VV<bool> same_poss;
V<VV<ll>> alp_list(12, VV<ll>(26)); 
ll H, W;

ll check_col(const VV<ll> &mat, V<bool> &used, ll wval, ll init_w1 = 0) {
    ll ret = 0;
    for(ll w1 = init_w1; w1 < W; w1++) {
        if(used[w1]) continue;
        for(ll w2 = w1 + 1; w2 < W; w2++) {
            if(used[w2]) continue;
            if(mat[w1][w2] != wval) continue;
            if(mat[w2][w1] != wval) continue;
            used[w1] = used[w2] = true;
            chmax(ret, check_col(mat, used, wval, (w1 + 1 == w2 ? w2 + 1 : w1 + 1)) + 1);
            used[w1] = used[w2] = false;
        }
    }
    return ret;
}

bool calc(const V<ll> &nodes) {
    VV<ll> mat(W, V<ll>(W, 0));
    for(ll i = 0; i + 1 < nodes.size(); i += 2) {
        ll f = nodes[i], t = nodes[i + 1];
        if(f == -1 || t == -1) return false;
        for(ll alp = 0; alp < 26; alp++) for(ll fe : alp_list[f][alp]) for(ll te : alp_list[t][alp]) mat[fe][te]++;
    }
    bool ret = false;
    V<bool> used(W, false);
    if(W & 1) {
        for(ll w = 0; w < W; w++) {
            if(mat[w][w] != nodes.size() / 2) continue;
            used[w] = true;
            ll tmp = check_col(mat, used, nodes.size() / 2);
            ret |= (tmp == W / 2);
            used[w] = false;
        }
    } else {
        ret = (check_col(mat, used, nodes.size() / 2) == W / 2);
    }
    return ret;
}

bool dfs(V<ll> &nodes, ll depth, ll max_d, V<bool> &used) {
    if((H & 1) && depth + 1 == max_d) {
        nodes[depth] = nodes[depth - 1];
        bool ret = calc(nodes);
        nodes[depth] = -1;
        return ret;
    }
    if(depth == max_d) return calc(nodes);
    bool ret = false;
    for(ll i = 0; i < H; i++) {
        if(used[i]) continue;
        if((depth & 1) && !(same_poss[i][nodes[depth - 1]])) continue;
        nodes[depth] = i;
        used[i] = true;
        ret |= dfs(nodes, depth + 1, max_d, used);
        if(ret) break;
        used[i] = false;
        nodes[depth] = -1;
    }
    return ret;
}

int main() {
    init_io();
    cin >> H >> W;
    for(ll i = 0; i < H; i++) {
        string s;
        cin >> s;
        S.push_back(s);
        for(ll j = 0; j < W; j++) alp_list[i][s[j] - 'a'].push_back(j);
    }
    
    {
        same_poss = VV<bool>(H, V<bool>(H, false));
        auto cpy = S;
        for(auto &s : cpy) sort(ALL(s));
        for(ll i = 0; i < H; i++) for(ll j = 0; j < H; j++) if(cpy[i] == cpy[j]) same_poss[i][j] = true;
    }

    V<ll> nodes(H + (H % 2), -1);
    V<bool> used(H + (H % 2), false);
    cout << (dfs(nodes, 0, H + (H % 2), used) ? "YES" : "NO") << endl;
    return 0;
}


Measured memory_bytes: 384