#include <bits/stdc++.h>
 
using namespace std;
 
const int MOD=1e9+7;
const double PI=3.14159265359;

vector<pair<int,int>> curPairs;
vector<vector<pair<int,int>>> allPairs;
vector<bool> chosen(20), ydone(20);

void getPairings(int n,int start=0){
    if(curPairs.size()==n/2) allPairs.push_back(curPairs);
    else{
        for(int i=start; i<n; i++){
            if(chosen[i]) continue;
            chosen[i]=true;
            for(int j=i+1; j<n; j++){
                if(chosen[j]) continue;
                //chosen[i]=true;
                chosen[j]=true;
                curPairs.push_back({i,j});
                getPairings(n, i);
                //chosen[i]=false;
                chosen[j]=false;
                curPairs.pop_back();
            }
            chosen[i]=false;
            //ydone[i]=true;
        }
        
    }
    
}

int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    int n,m;
    cin>>n>>m;
    
    vector<string> vs(n);
    for(auto&s:vs)cin>>s;
    
    vector<int> cts(26);
    for(auto v:vs){
        for(char c:v){
            cts[c-'a']++;
        }
    }
    int oct=0;
    for(int i=0; i<26; i++){
        oct+=cts[i]%2;
    }
    if(oct>1 || (n%2 && m%2 && !oct) || (oct && !min(n%2,m%2))){
        cout<<"NO";
        return 0;
    }
    if(n==1 || m==1){
        cout<<"YES";
        return 0;
    }
    //cout<<"YES";
    
    getPairings(n);
    
    vector<string> vt(n), vt2(m,string(n,'a'));
    
    for (auto& v:allPairs){
        int sz=v.size();
        for(int i=0; i<sz; i++){
            vt[i]=vs[v[i].first];
            vt[n-1-i]=vs[v[i].second];
        }
        if(n%2){
            vector<bool> used(n);
            for(auto p:v){
                used[p.first]=1;
                used[p.second]=1;
                
            }
            for(int i=0; i<n; i++){
                if(!used[i]){
                    vt[n/2]=vs[i];
                }
            }
        }
        for(int i=0; i<n; i++){
            //cout<<vt[i]<<endl;
            for(int j=0; j<m; j++){
                vt2[j][i]=vt[i][j];
            }
        }
        vector<bool> used(m);
        
        bool works=true, invUsed=false;
        for(int i=0; i<m && works; i++){
            if(used[i]) continue;
            auto s=vt2[i];
            //cout<<vt2[i]<<endl;
            reverse(s.begin(),s.end());
            bool found=false;
            for(int j=i+1; j<m && !found; j++){
                if(vt2[j]==s && !used[j]){
                    found=true;
                    used[i]=1;
                    used[j]=1;
                }
            }
            if(!found){
                //cout<<vt2[i]<<endl;
                if(m%2 && vt2[i]==s && !invUsed){
                    used[i]=true;
                    invUsed=true;
                }
                else{
                    works=false;
                }
            }
        }
        if(works){
            cout<<"YES";
            return 0;
        }
        
        
    }
    cout<<"NO";
    
    
    /*
    cout<<allPairs.size()<<endl;
    
    
    for(auto v: allPairs){
        for(auto p:v){
            cout<<"("<<p.first<<","<<p.second<<")";
        }
        cout<<endl;
    }
    
    */
   
    
    return 0;
}


Measured memory_bytes: 1212