#include<bits/stdc++.h>
using namespace std;
int h, w;
vector<string> s;
int used[20];
bool ans = false;
int cnt = 0;
bool equals(int x, int y) {
    for (int i = 0; i < h; i++) {
        if (s[i][x] != s[h-1-i][y]) return false;
    }
    return true;
}
bool check() {
    memset(used, 0, sizeof(used));
    bool f = false;
    for (int i = 0; i < w; i++) {
        if (used[i]) continue;
        bool ok = false;
        for (int j = i+1; j < w; j++) {
            if (used[j]) continue;
            if (equals(i, j)) {
                ok = true;
                used[j] = 1;
                break;
            }
        }
        if (!ok) {
            if (w % 2 == 0 || f) return false;
            f = true;
        }
    }
    return true;
}
void dfs(int cur, bool even) {
    if (cur >= (h-1) / 2) {
        //cout << "\n";
        //for (string &str : s) cout << str << "\n";
        ans |= check();
        return;
    }
    if (even) {
        swap(s[cur], s[h/2]);
        for (int j = cur + 1; j < h - cur; j++) {
            swap(s[j], s[h-1-cur]);
            dfs(cur+1, even);
            swap(s[j], s[h-1-cur]);
        }
        swap(s[cur], s[h/2]);
    }
    for (int j = cur + 1; j < h - cur; j++) {
        swap(s[j], s[h-1-cur]);
        dfs(cur+1, even);
        swap(s[j], s[h-1-cur]);
    }
}
int main() {
    cin >> h >> w;
    s.resize(h);
    for (int i = 0; i < h; i++) {
        cin >> s[i];
    }
    dfs(0, h % 2 == 1);
    if (ans) cout << "YES\n";
    else cout << "NO\n";
    return 0;
}
