#include <bits/stdc++.h>
using namespace std;
using ll = long long;

#ifdef PA_DEBUG
void print(vector<string> const &chars, int line, vector<pair<int,int>> const &pairs) {
    for (int k = 0; k < static_cast<int>(pairs.size()); k++)
        if (pairs[k].first != -1) cerr << chars[line][pairs[k].first];
    if (pairs[0].first == -1) cerr << chars[line][pairs[0].second];
    for (int k = static_cast<int>(pairs.size())-1; k >= 0; k--)
        if (pairs[k].first != -1) cerr << chars[line][pairs[k].second];
}
#endif

bool check(vector<string> const &chars, vector<pair<int,int>> const &pairs) {
    int h = chars.size();
    vector<bool> paired(h);
#ifdef PA_DEBUG
    cerr << "paired cols: ";
    for (auto const &p: pairs) cerr << "(" << p.first << "," << p.second << ") ";
    cerr << endl;
#endif

    for (int i = 0; i < h; i++) {
        if (paired[i]) continue;
        for (int j = i+1; j < h; j++) {
            if (paired[j]) continue;

            bool is_reverse = true;
            for (auto const &x: pairs) {
                if (x.first == -1) {
                    if (chars[i][x.first] != chars[j][x.first]) {
                        is_reverse = false;
                        break;
                    }
                } else if (chars[i][x.first] != chars[j][x.second] || chars[i][x.second] != chars[j][x.first]) {
                    is_reverse = false;
                    break;
                }
            }

            if (is_reverse) {
#ifdef PA_DEBUG
                cerr << "    paired: ";
                print(chars, i, pairs);
                cerr << " (" << i << ") and ";
                print(chars, j, pairs);
                cerr << " (" << j << ")" << endl;
#endif
                paired[i] = paired[j] = true;
                break;
            }
        }
    }

    if (count(paired.begin(), paired.end(), false) > 1) {
#ifdef PA_DEBUG
        cerr << "    ... but there are " << count(paired.begin(), paired.end(), false) <<  " no-pair(s)." << endl;
#endif
        return false;
    }

    if (h&1) {
        for (int i = 0; i < h; i++) {
            if (paired[i]) continue;
#ifdef PA_DEBUG
            cerr << "    last line is ";
            print(chars, i, pairs);
            cerr << endl;
#endif
            for (auto const &x: pairs) {
                if (x.first == -1) continue;
                if (chars[i][x.first] != chars[i][x.second]) {
#ifdef PA_DEBUG
                    cerr << "    ... but this line is not palindrome." << endl;
#endif
                    return false;
                }
            }
        }
    }
    return true;
}

bool calc(vector<string> const &chars, unordered_map<int, bool> &paired, int w, vector<pair<int,int>> &pairs) {
    if (static_cast<int>(pairs.size()) == (w+1)/2) {
        return check(chars, pairs);
    } else {
        for (int x1 = (w&1 ? -1 : 0); x1 < w; x1++) {
            if (paired[x1]) continue;
            for (int x2 = x1+1; x2 < w; x2++) {
                if (paired[x2]) continue;

                paired[x1] = paired[x2] = true;
                pairs.push_back(make_pair(x1, x2));
                if (calc(chars, paired, w, pairs)) return true;
                pairs.pop_back();
                paired[x1] = paired[x2] = false;
            }
            break;
        }
    }
    return false;
}

int main() {
    int h, w;
    cin >> h >> w;
    vector<string> chars(h);
    for (int i = 0; i < h; i++) cin >> chars[i];
#ifdef PA_DEBUG
    cerr << "input: " << endl;
    for (auto const &l: chars) {
        cerr << "    " << l << endl;
    }
#endif

    unordered_map<int, bool> paired(w);
    vector<pair<int,int>> pairs; pairs.reserve(w/2);
    cout << (calc(chars, paired, w, pairs) ? "YES" : "NO") << endl;

    return 0;
}



Measured memory_bytes: 256