#include <bits/stdc++.h>

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef unsigned int ui32;
const long long INFLL = 1e18;

using namespace std;

bool can(string s1, string s2) {
    if (s1[0] != s2.back() || s1.back() != s2[0]) {
        return false;
    }
    vector<int> cnt(26, 0);
    for (auto ch : s1) {
        ++cnt[ch - 'a'];
    }
    for (auto ch : s2) {
        --cnt[ch - 'a'];
    }
    for (int i = 0; i < 26; i++) {
        if (cnt[i]) {
            return false;
        }
    }
    int n = (int)s1.size();
    for (int i = 1, j = n - 2; i < j; i++, j--) {
        bool ok = false;
        for (int l = i; l <= j && !ok; l++) {
            for (int r = i; r <= j && !ok; r++) {
                if (l == r) {
                    continue;
                }
                if (s1[l] == s2[r] && s1[r] == s2[l]) {
                    ok = true;
                    swap(s1[i], s1[l]);
                    swap(s1[j], s1[r]);
                    swap(s2[i], s2[l]);
                    swap(s2[j], s2[r]);
                }
            }
        }
        if (!ok) {
            return false;
        }
    }
    reverse(s2.begin(), s2.end());
    assert(s1 == s2);
    return true;
}

void swapCol(vector<string> &vec, int l, int r) {
    int n = (int)vec.size();
    for (int i = 0; i < n; i++) {
        swap(vec[i][l], vec[i][r]);
    }
}

int calc(int mask) {
    int cnt = 0;
    for (int i = 0; i < 30; i++) {
        if (mask & (1 << i)) {
            ++cnt;
        }
    }
    return cnt;
}

bool go(vector<string> vec) {
    if (vec.empty() || vec[0].empty()) {
        return true;
    }
    int n = (int)vec.size();
    int m = (int)vec[0].size();
    if (n == 1) {
        int mask = 0;
        for (int i = 0; i < m; i++) {
            mask ^= (1 << (vec[0][i] - 'a'));
        }
        return calc(mask) <= 1;
    }
    if (m == 1) {
        int mask = 0;
        for (int i = 0; i < n; i++) {
            mask ^= (1 << (vec[i][0] - 'a'));
        }
        return calc(mask) <= 1;
    }
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < n; j++) {
            if (i == j) {
                continue;
            }
            for (int l = 0; l < m; l++) {
                for (int r = 0; r < m; r++) {
                    if (l == r) {
                        continue;
                    }
                    swapCol(vec, 0, l);
                    swapCol(vec, r, m - 1);
                    swap(vec[0], vec[i]);
                    swap(vec[j], vec[n - 1]);
                    if (!can(vec[0], vec[n - 1])) {
                        swapCol(vec, 0, l);
                        swapCol(vec, r, m - 1);
                        swap(vec[0], vec[i]);
                        swap(vec[j], vec[n - 1]);
                        continue;
                    }
                    string t1, t2;
                    for (int k = 0; k < n; k++) {
                        t1 += vec[k][0];
                        t2 += vec[k][m - 1];
                    }
                    if (!can(t1, t2)) {
                        swapCol(vec, 0, l);
                        swapCol(vec, r, m - 1);
                        swap(vec[0], vec[i]);
                        swap(vec[j], vec[n - 1]);
                        continue;
                    }
                    vector<string> nw(n - 2);
                    for (int x = 1; x < n - 1; x++) {
                        for (int y = 1; y < m - 1; y++) {
                            nw[x - 1] += vec[x][y];
                        }
                    }
                    return go(nw);
                }
            }
        }
    }
    return false;
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    //freopen("input.txt", "r", stdin);
    //freopen("input.txt", "w", stdout);

    int h, w;
    cin >> h >> w;
    vector<string> vec;
    for (int i = 0; i < h; i++) {
        string s;
        cin >> s;
        vec.push_back(s);
    }
    if (go(vec)) {
        cout << "YES\n";
    } else {
        cout << "NO\n";
    }
    return 0;
}


Measured memory_bytes: 256