/**
 *    author:  otera    
**/
#include<iostream>
#include<string> 
#include<cstdio>
#include<cstring>
#include<vector>
#include<cmath>
#include<algorithm> 
#include<functional>
#include<iomanip>
#include<queue>
#include<deque>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<complex>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<utility>
#include<cassert>
using namespace std;

//#define int long long
typedef long long ll;
typedef unsigned long long ul;
typedef unsigned int ui;
typedef long double ld;
const int inf=1e9+7;
const ll INF=1LL<<60 ;
const ll mod=1e9+7 ;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
typedef complex<ld> Point;
const ld eps = 1e-8;
const ld pi = acos(-1.0);
typedef pair<int, int> P;
typedef pair<ld, ld> LDP;
typedef pair<ll, ll> LP;
#define fr first
#define sc second
#define all(c) c.begin(),c.end()
#define pb push_back
#define debug(x)  cerr << #x << " = " << (x) << endl;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

int h, w;
vector<vector<char>> s;

void dfs(vector<int>& used, int i, bool ok) {
    if(i == h) {
        //
        vector<bool> u(h, 0);
        deque<int> que1, que2;
        int mid = -1;
        rep(j, h) {
            if(!u[j]) {
                if(used[j] == j) {
                    mid = j;
                    u[j] = j;
                    continue;
                }
                que1.push_back(j); que2.push_back(used[j]);
                u[used[j]] = 1, u[j] = 1;
            }
        }
        vector<vector<char>> f(h, vector<char>(w, '?'));
        int cur = 0;
        while(que1.size()) {
            int j = que1.front(); que1.pop_front();
            rep(k, w) {
                f[cur][k] = s[j][k];
            }
            ++ cur;
        }
        if(mid != -1) {
            rep(k, w) {
                f[cur][k] = s[mid][k];
            }
            ++ cur;
        }
        while(que2.size()) {
            int j = que2.back(); que2.pop_back();
            rep(k, w) {
                f[cur][k] = s[j][k];
            }
            ++ cur;
        }
        // rep(i, h) {
        //     rep(j, w) {
        //         cerr << f[i][j];
        //     }
        //     cerr << endl;
        // }
        // cerr << endl;
        bool check = 1;
        map<string, int> mp;
        rep(j, w) {
            string res = "";
            rep(k, h) res += f[k][j];
            mp[res] ++;
        }
        int mi = 0;
        for(auto x: mp) {
            string tmp = x.fr; int co = x.sc;
            if(co == -1) continue;
            string tmp1 = tmp; reverse(all(tmp1));
            if(tmp == tmp1) {
                if(co % 2 == 1) ++ mi;
            } else {
                if(abs(co - mp[tmp1]) == 1) {
                    ++ mi;
                    mp[tmp1] = -1;
                } else if(co == mp[tmp1]) {
                    mp[tmp1] = -1;
                    continue;
                }
                else {
                    check = 0;
                }
            }
        }
        if(w % 2 == 1) {
            if(mi == 1 && check) check = 1;
            else check = 0;
        } else {
            if(mi == 0 && check) check = 1;
            else check = 0;
        }
        //
        if(check) {
            cout << "YES" << endl;
            exit(0);
        }
        return;
    }
    if(used[i] != -1) {
        dfs(used, i + 1, ok);
        return;
    }
    if(ok) {
        used[i] = i;
        ok = 0;
        dfs(used, i + 1, ok);
        ok = 1;
        used[i] = -1;
    }
    for(int j = i + 1; j < h; ++ j) {
        if(used[j] != -1) continue;
        used[i] = j, used[j] = i;
        dfs(used, i + 1, ok);
        used[i] = -1, used[j] = -1;
    }
}

void solve() {
	cin >> h >> w;
    s.assign(h, vector<char>(w));
    rep(i, h) {
        rep(j, w) {
            cin >> s[i][j];
        }
    }
    vector<int> used(h, -1);
    bool ok = (h % 2);
    dfs(used, 0, ok);
    cout << "NO" << endl;
}

signed main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	//cout << fixed << setprecision(10);
	//int t; cin >> t; rep(i, t)solve();
	solve();
    return 0;
}

Measured memory_bytes: 3560