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

typedef pair<int,int> P;

bool countcheck(const string &a,const string &b){
  vector<int> A(26,0);
  vector<int> B(26,0);
  for(int i=0;i<(int)a.size();i++){
    A[ a[i]-'a' ]++;
    B[ b[i]-'a' ]++;
  }
  return (A==B);
}

vector<int> func(const string &a,const string &b){
  vector<int> res( a.size() ,0 );
  for(int i=0;i<(int)a.size();i++){
    for(int j=0;j<(int)b.size();j++){
      if(a[i]==b[j])
        res[i]|=(1<<j);
    }
  }
  return res;
}

vector<int> G[12];
bool visited[12];
void dfs(int pos,int &sz){
  visited[pos]=true;
  sz++;
  for(int to:G[pos]){
    if(visited[to])continue;
    dfs(to,sz);
  }
}

bool judge(const vector<string> &a, const vector<string> &b){

  /*
  cout<<"------------"<<endl;
  for(string str:a)cout<<str<<endl;
  cout<<endl;
  for(string str:b)cout<<str<<endl;
    cout<<"------------"<<endl;
  */
  
  vector<int> total( a[0].size() , (1<<20)-1 );
  
  for(int i=0;i<(int)a.size();i++){
    if(!countcheck(a[i],b[i]))return false;
  }

  for(int i=0;i<(int)a.size();i++){
    vector<int> X=func(a[i],b[i]);
    vector<int> Y=func(b[i],a[i]);
    for(int j=0;j<(int)X.size();j++){
      int tmp=(X[j]&Y[j]);
      if(tmp == 0 )return false;
    }
  }
  
  for(int i=0;i<(int)a.size();i++){
    vector<int> X=func(a[i],b[i]);
    vector<int> Y=func(b[i],a[i]);
    for(int j=0;j<(int)X.size();j++){
      int tmp=(X[j]&Y[j]);
      total[j]=(total[j]&tmp);
      if(total[j]==0)return false;
    }
  }

  for(int i=0;i<12;i++){
    G[i].clear();
    visited[i]=false;
  }

  //  cout<<a[0]<<' '<<b[0]<<endl;
  for(int i=0;i<(int)total.size();i++){
    for(int j=0;j<(int)total.size();j++){
      if( total[i] >> j &1 ){
        //        cout<<i<<' '<<j<<endl;
        G[i].push_back(j);
        G[j].push_back(i);
      }
    }
  }

  int cc=0;
  for(int i=0;i<(int)a[0].size();i++){
    if(visited[i])continue;
    int sz=0;
    dfs(i,sz);

    cc += (sz%2);
  }
  return (cc<=1);
}

bool check( vector<string> &a,const vector<string> &b){
  sort(a.begin(),a.end());
  do{
    if( judge(a,b) )return true;
  }while( next_permutation( a.begin(), a.end() ) );
  return false;
}

bool solve(const vector<string> &t ){
  int H=t.size();

  int h=H/2;
  for(int bit=0;bit<(1<<H);bit++){
    if(__builtin_popcount(bit)!=h)continue;
    
    vector<string> a,b;
    for(int i=0;i<H;i++){
      if(bit>>i&1)a.push_back(t[i]);
      else b.push_back(t[i]);
    }

    if( check(a,b) )return true;

  }

  return false;
}

int main(){
  int H,W;
  cin>>H>>W;


  vector<string> t(H);
  for(int i=0;i<H;i++){
    cin>>t[i];
  }

  if(H==1&&W==1){
    cout<<"YES"<<endl;
    return 0;
  }

  if(H==1 || W==1){
    map<char,int> mp;
    for(int i=0;i<H;i++)
      for(int j=0;j<W;j++)
        mp[ t[i][j] ]++;

    int count=0;
    for(int i=0;i<H;i++)
      for(int j=0;j<W;j++)
        if( mp[ t[i][j] ] %2 == 1 )
          count++;
    if( count <= 1 )cout<<"YES"<<endl;
    else cout<<"NO"<<endl;
    return 0;
  }
  
  if( H%2==0 ){
    cout<< ( solve(t) ? "YES" : "NO" ) <<endl;
  }else{
    //    assert(0);
    
    bool flag=false;
    vector<string> u;
    for(int i=0;i<H;i++){
      u=t;
      u.push_back(t[i]);
      if( solve(u) ){
        flag=true;
        break;
      }
    }
    if(flag){
      cout<<"YES"<<endl;
    }else{
      cout<<"NO"<<endl;
    }
  }
  return 0;
}


Measured memory_bytes: 256