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

int nth_bit(int64_t num, int n){
    return (num >> n) & 1;
}

int H, W;
string S[12];

vector<vector<pair<int, int>>> cand;
vector<pair<int, int>> now;

void rec(int b){
    if(b == (1<<H)-1){
        cand.push_back(now);
        return;
    }

    vector<int> avail;
    for(int i=0; i<H; i++) if(!nth_bit(b, i)) avail.push_back(i);
    int sz = avail.size();
    int f = avail[0];
    if(sz%2){
        now.emplace_back(f, f);
        rec(b+(1<<f));
        now.pop_back();
    }
    for(int i=1; i<sz; i++){
        int g = avail[i];
        now.emplace_back(f, g);
        rec(b+(1<<f)+(1<<g));
        now.pop_back();
    }
}

int main(){
    cin >> H >> W;
    for(int i=0; i<H; i++) cin >> S[i];
    rec(0);
    for(auto& v : cand){
        int sz = v.size();
        vector<int> order;
        for(int i=0; i<sz; i++) order.push_back(v[i].first);
        for(int i=sz-1; i>=0; i--) order.push_back(v[i].second);

        multiset<string> st;
        for(int j=0; j<W; j++){
            string s;
            for(int i : order) s.push_back(S[i][j]);
            st.insert(s);
        }

        bool one_done = false, success = true;
        while(st.size() && success){
            auto it = st.begin();
            string s = *it, sr = *it;
            st.erase(it);
            reverse(sr.begin(), sr.end());
            auto it2 = st.find(sr);
            if(it2 != st.end()){
                st.erase(it2);
            }else if(!one_done && s == sr){
                one_done = true;
            }else{
                success = false;
            }
        }
        if(success){
            cout << "YES" << endl;
            return 0;
        }
    }
    cout << "NO" << endl;
}