#include "bits/stdc++.h"
using namespace std;
using ll     = long long;
using pii    = pair<int, int>;
using pll    = pair<ll, ll>;
using vi     = vector<int>;
using vl     = vector<ll>;
using vvi    = vector<vi>;
using vvl    = vector<vl>;
const ll INF = 1LL << 60;
const ll MOD = 1000000007;
template <class T>
bool chmax(T &a, const T &b) {
    return (a < b) ? (a = b, 1) : 0;
}
template <class T>
bool chmin(T &a, const T &b) {
    return (b < a) ? (a = b, 1) : 0;
}
template <class C>
void print(const C &c, std::ostream &os = std::cout) {
    std::copy(std::begin(c), std::end(c), std::ostream_iterator<typename C::value_type>(os, " "));
    os << std::endl;
}

int main() {
    int h, w;
    cin >> h >> w;
    vector<string> s(h);
    for (int i = 0; i < h; ++i) {
        cin >> s[i];
    }
    if (h % 2 == 1) {
        h++;
        s.emplace_back(w, '*');
    }
    int cnt                                                  = 0;
    function<void(vector<string> &, vector<string> &)> check = [&](vector<string> &perm1, vector<string> &perm2) {
        cnt++;
        reverse(perm2.begin(), perm2.end());
        vector<string> t(w, "");
        for (int i = 0; i < w; ++i) {
            for (int j = 0; j < h / 2; ++j) {
                t[i] += perm1[j][i];
            }
            for (int j = 0; j < h / 2; ++j) {
                t[i] += perm2[j][i];
            }
        }
        int mask = 0;
        int odd  = w % 2;
        for (int i = 0; i < w; ++i) {
            if (mask & 1 << i)
                continue;
            mask |= 1 << i;
            bool ok = false;
            for (int j = 0; j < w; ++j) {
                bool oktemp = true;
                if (mask & 1 << j)
                    continue;
                for (int k = 0; k < h; ++k) {
                    if (t[i][k] != t[j][h - 1 - k] && (t[i][k] != '*' && t[j][h - 1 - k] != '*')) {
                        oktemp = false;
                        break;
                    }
                }
                if (oktemp) {
                    mask |= 1 << j;
                    ok = true;
                    break;
                }
            }
            if (!ok) {
                odd--;
                if (odd < 0) {
                    return;
                }
            }
        }
        cout << "YES"
             << "\n";
        exit(0);
    };
    function<void(int, vector<string>, vector<string>)> dfs = [&](int mask, vector<string> perm1,
                                                                  vector<string> perm2) {
        if (__builtin_popcount(mask) == h) {
            check(perm1, perm2);
            return;
        }
        int idx = -1;
        for (int i = 0; i < h; ++i) {
            if (~mask & (1 << i)) {
                idx = i;
                break;
            }
        }
        mask |= 1 << idx;
        perm1.push_back(s[idx]);
        for (int i = 0; i < h; ++i) {
            if (~mask & (1 << i)) {
                vector<string> permt = perm2;
                permt.push_back(s[i]);
                dfs(mask | (1 << i), perm1, permt);
            }
        }
    };
    vector<string> perm1, perm2;
    dfs(0, perm1, perm2);
    cout << "NO"
         << "\n";
    cerr << cnt << endl;
    return 0;
}

Measured memory_bytes: 384