#include <iostream>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <cstring>
#include <chrono>
#include <vector>
#include <map>
#include <random>
#include <set>
#include <algorithm>
#include <math.h>
#include <cstdio>
#include <stdio.h>
#include <queue>
#include <bitset>
#include <cstdlib>
#include <deque>
#include <cassert>
#include <stack>
using namespace std;

#define mp make_pair
#define f first
#define se second
#define pb push_back
#define ppb pop_back
#define emb emplace_back
#define ll long long
#define ull unsigned long long
#define cntbit(x) __builtin_popcount(x)
#define endl '\n'
#define uset unordered_set
#define umap unordered_map
#define all(x) x.begin(), x.end()
#define pii pair<int, int>
#define ld long double
#define pll pair<long long, long long>

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

template <typename T> inline T range(T l, T r) {
    return uniform_int_distribution<T>(l, r)(rng);
}

inline void setin(string s) {
    freopen(s.c_str(), "r", stdin);
}

inline void setout(string s) {
    freopen(s.c_str(), "w", stdout);
}

template <typename T> void Min(T &a, T b) {
    a = min(a, b);
}

template <typename T> void Max(T &a, T b) {
    a = max(a, b);
}

const int inf = 0x3f3f3f3f;
const int mod = 1e9 + 7;
const int N = 13;
int n, m, a[N][N], b[N][N];
bool used[N];
int ans;
bool was, was2;

vector <vector <pii>> is;

vector <pii> cur;

string s[N];

bool used2[N];

void recm(int i) {
    if(i == m) {
        cout << "YES" << endl;
        exit(0);
    }
    else {
        if(used2[i])
            recm(i + 1);
        else {
            if(m % 2 == 1 && !was2) {
                was2 = true;
                bool flag = true;
                for(pii e : cur)
                    if(s[e.f][i] != s[e.se][i]) {
                        flag = false;
                        break;
                    }
                if(flag)
                    recm(i + 1);
                was2 = false;
            }
            for(int j = i + 1; j < m; ++j)
                if(!used2[j]) {
                    used2[j] = true;
                    bool flag = true;
                    for(pii e : cur)
                        if(s[e.f][i] != s[e.se][j] || s[e.se][i] != s[e.f][j]) {
                            flag = false;
                            break;
                        }
                    if(flag)
                        recm(i + 1);
                    used2[j] = false;
                }
        }
    }
}

void rec(int i) {
    if(i == n)
        recm(0);
    else {
        if(used[i])
            rec(i + 1);
        else {
            if(n % 2 == 1 && !was) {
                was = true;
                cur.pb({i, i});
                rec(i + 1);
                cur.ppb();
                was = false;
            }
            for(int j = i + 1; j < n; ++j)
                if(!used[j]) {
                    used[j] = true;
                    cur.pb({i, j});
                    rec(i + 1);
                    cur.ppb();
                    used[j] = false;
                }
        }
    }
}


inline string reversed(string x) {
    reverse(x.begin(), x.end());
    return x;
}

inline bool check(const vector <pii> &x, const vector <pii> &y) {
    for(pii e : x)
        for(pii e2 : y)
            if(s[e.f][e2.f] != s[e.se][e2.se] || s[e.f][e2.se] != s[e.se][e2.f])
                return false;
    return true;
}

main() {
    ios_base::sync_with_stdio(0); cout.tie(0); cin.tie(0);
    // setin("input.txt");
    cin >> n >> m;
    for(int i = 0; i < n; ++i)
        cin >> s[i];
    rec(0);
    cout << "NO" << endl;
    return 0;
}


Measured memory_bytes: 256