#include "bits/stdc++.h"
using namespace std;
typedef long long li;

int n, m;

template <class T>
vector<vector<pair<T, T>>> enumerate_pairs(const vector<T>& items) {
    auto result = vector<vector<pair<T, T>>>();
    if (items.empty()) {
        return {{}};
    }
    for (int i = 1; i < items.size(); ++i) {
        auto p = make_pair(items[0], items[i]);
        auto subitems = vector<T>();
        for (int j = 1; j < items.size(); ++j) {
            if (j != i) {
                subitems.push_back(items[j]);
            }
        }
        auto sub_results = enumerate_pairs(subitems);
        for (auto &&pairs: sub_results) {
            pairs.push_back(p);
            result.push_back(pairs);
        }
    }
    return result;
};

bool validate_columns(vector<string>& rs) {
    vector<string> cols(m);
    for (int i = 0; i < n; ++i) {
        for (int j = 0; j < m; ++j) {
            cols[j].push_back(rs[i][j]);
        }
    }

    vector<string> rev_cols = cols;
    for (int k = 0; k < m; ++k) {
        reverse(cols[k].begin(), cols[k].end());
    }

    bool any_matchable = false;
    vector<vector<int>> matchable(m, vector<int>(m, 0));
    for (int i = 0; i < m; ++i) {
        for (int j = 0; j < m; ++j) {
            matchable[i][j] = cols[i] == rev_cols[j];
            any_matchable |= matchable[i][j];
        }
    }

    if (not any_matchable) {
        return false;
    }


    vector<bool> dp(1 << m, false);
    for (int mask = 0; mask < (1 << m); ++mask) {
        if (mask == 0) {
            dp[mask] = true;
        } else if (__builtin_popcount(mask) == 1) {
            for (int i = 0; i < m; ++i) {
                if ((mask & (1 << i)) == 0) {
                    continue;
                }
                int prev = mask - (1 << i);
                if (dp[prev] && matchable[i][i]) {
                    dp[mask] = true;
                }
            }
        } else {
            for (int i = 0; i < m; ++i) {
                if ((mask & (1 << i)) == 0) {
                    continue;
                }
                for (int j = 0; j < i; ++j) {
                    if ((mask & (1 << j)) == 0) {
                        continue;
                    }
                    int prev = mask - (1 << i) - (1 << j);
                    if (dp[prev] && matchable[i][j]) {
                        dp[mask] = true;
                    }
                }
            }
        }
    }

    return dp[(1 << m) - 1];
}

int main() {
    cin >> n >> m;
    vector<string> rows(n);
    for (int i = 0; i < n; ++i) {
        cin >> rows[i];
    }

    vector<int> perm;
    for (int i = 0; i < n; ++i) {
        perm.push_back(i);
    }

    if (n & 1) {
        perm.push_back(-1);
    }

    for (auto &&pairs  : enumerate_pairs(perm)) {
        vector<int> head, tail, mid;
        for (auto &&pair  : pairs) {
            int p = pair.first;
            int q = pair.second;

            if (p == -1) {
                mid.push_back(q);
            } else if (q == -1) {
                mid.push_back(p);
            } else {
                head.push_back(p);
                tail.push_back(q);
            }
        }
        reverse(tail.begin(), tail.end());

        vector<int> actual_perm;
        actual_perm.insert(actual_perm.end(), head.begin(), head.end());
        actual_perm.insert(actual_perm.end(), mid.begin(), mid.end());
        actual_perm.insert(actual_perm.end(), tail.begin(), tail.end());

        vector<string> rs;
        for (auto &&i : actual_perm) {
            rs.push_back(rows[i]);
        }
        if (validate_columns(rs)) {
            cout << "YES" << endl;
            return 0;
        }
    }

    cout << "NO" << endl;
    return 0;
}


Measured memory_bytes: 1468