#pragma GCC optimize("Ofast")
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>

#define F first
#define S second
//#define int long long
#define ll long long
#define int  unsigned long long
#define pb push_back
//#define double long double

using namespace std;
using namespace __gnu_pbds;
typedef  tree< int , null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
const int mod = 1e9 + 7;
const int N = 25;
const int K = 250;
const int base = 26;
int used[N], b[N], c[N], a[N][N], p[N], n, m, cntt, bb[N];
map < int, int > cnt1, cnt2;
void gen(int x){
    if (x % 2){
        for (int i = 1; i <= m; i++){
            if (!used[i]){
                used[i] = 1;
                p[(m + 1) / 2] = i;
                for (int j = 1; j <= n; j++){
                    cnt1[b[j]]--;
                    cnt2[c[j]]--;
                    b[j] += bb[(m + 1) / 2] * a[j][i];
                    c[j] += bb[m - (m + 1) / 2 + 1] * a[j][i];
                    cnt1[b[j]]++;
                    cnt2[c[j]]++;
                }
                int f = 1;
                for (int l = 1; l <= n; l++) if (b[l] != c[l] && cnt1[c[l]] != cnt2[c[l]]){
                    f = 0;
                    break;
                }
                if (f == 1) gen(x - 1);
                for (int j = 1; j <= n; j++){
                    cnt1[b[j]]--;
                    cnt2[c[j]]--;
                    b[j] -= bb[(m + 1) / 2] * a[j][i];
                    c[j] -= bb[m - (m + 1) / 2 + 1] * a[j][i];
                    cnt1[b[j]]++;
                    cnt2[c[j]]++;
                }
                used[i] = 0;
            }
        }
    } else{
        if (x == 0){
            if (n % 2){
                cnt1.clear();
                cnt2.clear();
                for (int j = 1; j <= n; j++){
                    cnt1[b[j]]++;
                    cnt2[c[j]]++;
                }
                int w = -1;
                int res = 1;
                for (int j = 1; j <= n; j++){
                    if (c[j] == b[j]){
                        if (cnt1[c[j]] % 2 != 0){
                            if (w == -1 || w == c[j]){
                                w = c[j];
                                continue;
                            }
                            res = 0;
                            break;
                        }
                    } else if (cnt1[c[j]] != cnt2[c[j]]){
                        res = 0;
                        break;
                    }
                }
                if (res && w != -1){
                    cout << "YES";
                    exit(0);
                }
            } else{
                int res = 1;
                for (int i = 1; i <= n; i++){
                    if (c[i] == b[i]){
                        if (cnt1[c[i]] % 2 != 0){
                            res = 0;
                            break;
                        }
                    } else if (cnt1[c[i]] != cnt2[c[i]]){
                        res = 0;
                        break;
                    }
                }
                if (res){
                    cout << "YES";
                    exit(0);
                }
            }
        } else{
            for (int i = 1; i <= m; i++){
                if (used[i]) continue;
                for (int j = i + 1; j <= m; j++){
                    if (used[j]) continue;
                    used[i] = 1;
                    used[j] = 1;
                    int q = (m - x) / 2 + 1;
                    p[q] = i;
                    p[m - q + 1] = j;
                    for (int l = 1; l <= n; l++){
                        cnt1[b[l]]--;
                        cnt2[c[l]]--;
                        b[l] += bb[q] * a[l][i];
                        b[l] += bb[m - q + 1] * a[l][j];
                        c[l] += bb[m - q + 1] * a[l][i];
                        c[l] += bb[q] * a[l][j];
                        cnt1[b[l]]++;
                        cnt2[c[l]]++;
                    }
                    int f = 1;
                    for (int l = 1; l <= n; l++) if (c[l] != b[l] && cnt1[c[l]] != cnt2[c[l]]){
                        f = 0;
                        break;
                    }
                    if (f) gen(x - 2);
                    used[i] = 0;
                    used[j] = 0;
                    for (int l = 1; l <= n; l++){
                        cnt1[b[l]]--;
                        cnt2[c[l]]--;
                        b[l] -= bb[q] * a[l][i];
                        b[l] -= bb[m - q + 1] * a[l][j];
                        c[l] -= bb[m - q + 1] * a[l][i];
                        c[l] -= bb[q] * a[l][j];
                        cnt1[b[l]]++;
                        cnt2[c[l]]++;
                    }
                }
            }
        }
    }
}
main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
   // freopen("input.txt", "r", stdin);
    cin >> n >> m;
    for (int i = 1; i <= n; i++){
        string s;
        cin >> s;
        for (int j = 1; j <= m; j++) a[i][j] = s[j - 1] - 'a';
    }
    bb[1] = 1;
    cnt1[0] = n;
    cnt2[0] = n;
    for (int i = 2; i <= m; i++){
        bb[i] = bb[i - 1] * base;
    }
    gen(m);
   // cout << cntt << endl;
    cout << "NO";
}


Measured memory_bytes: 6400