#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <bits/stdc++.h>

using namespace __gnu_pbds;
using namespace std;

using ll = long long;
using ld = long double;

#define mp make_pair

typedef tree<
        pair<int, int>,
        null_type,
        less<pair<int, int>>,
        rb_tree_tag,
        tree_order_statistics_node_update>
        ordered_set;


const int p = 1000000007;


int mul(int a, int b) {
    return (1LL * a * b) % p;
}

int add(int a, int b) {
    int s = (a+b);
    if (s>=p) s-=p;
    return s;
}

int sub(int a, int b) {
    int s = (a+p-b);
    if (s>=p) s-=p;
    return s;
}

int po(int a, int deg)
{
    if (deg==0) return 1;
    if (deg%2==1) return mul(a, po(a, deg-1));
    int t = po(a, deg/2);
    return mul(t, t);
}

int inv(int n)
{
    return po(n, p-2);
}


mt19937 rnd(time(0));

/*
const int N = 1200000;

vector<int> facs(N), invfacs(N);

void init()
{
    facs[0] = 1;
    for (int i = 1; i<N; i++) facs[i] = mul(facs[i-1], i);
    invfacs[N-1] = inv(facs[N-1]);
    for (int i = N-2; i>=0; i--) invfacs[i] = mul(invfacs[i+1], i+1);
}

int C(int n, int k)
{*
    if (n<k) return 0;
    return mul(facs[n], mul(invfacs[k], invfacs[n-k]));
}
*/

int h, w;

vector<int> produce(vector<int> a)
{
    int mid = -1;
    vector<int> st;
    vector<int> en;
    set<int> cur;

    if (h%2==0)
    {
        for (int i = 0; i<h; i++) cur.insert(i);
    }
    else
    {
        for (int i = -1; i<h; i++) cur.insert(i);
    }
    for (int i = 0; i<(h+1)/2; i++)
    {
        vector<int> lol(cur.begin(), cur.end());
        int l = lol[0];
        int r = lol[a[i]];
        cur.erase(l); cur.erase(r);
        if (l==-1 || r==-1) mid = (l + r + 1);
        else
        {
            st.push_back(l);
            en.push_back(r);
        }
    }

    vector<int> ans;
    for (auto it: st) ans.push_back(it);
    if (mid!=-1) ans.push_back(mid);
    reverse(en.begin(), en.end());
    for (auto it: en) ans.push_back(it);
    return ans;
}

bool check_pal(string s)
{
    string t = s;
    reverse(t.begin(), t.end());
    return (s==t);
}

bool check_even(vector<string> a)
{
    if (a.size()==0) return true;
    string s = a[0];
    reverse(s.begin(), s.end());
    for (int i = 1; i<a.size(); i++)
    {
        if (s==a[i])
        {
            vector<string> b;
            for (int j = 1; j<i; j++) b.push_back(a[j]);
            for (int j = i+1; j<a.size(); j++) b.push_back(a[j]);
            return check_even(b);
        }
    }
    return false;
}

bool check(vector<string> a)
{
    if (a.size()%2==0) return check_even(a);
    for (int i = 0; i<a.size(); i++) if (check_pal(a[i]))
    {
        vector<string> a1;
        for (int j = 0; j<i; j++) a1.push_back(a[j]);
        for (int j = i+1; j<a.size(); j++) a1.push_back(a[j]);
        if (check_even(a1)) return true;
    }
    return false;
}


int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(nullptr);


    //h = 12; w = 12;

    cin>>h>>w;
    vector<string> a(h);
    for (int i = 0; i<h; i++) cin>>a[i];

    vector<vector<int>> shit(1);

    int H = h;
    if (H%2) H++;
    while (H)
    {
        vector<vector<int>> shit1;
        for (auto it: shit)
        {
            for (int i = 1; i<=H-1; i++)
            {
                vector<int> tmp(it);
                tmp.push_back(i);
                shit1.push_back(tmp);
            }
        }
        shit = shit1;
        H-=2;
    }

    vector<vector<int>> perms;
    for (auto it: shit) perms.push_back(produce(it));

    /*for (auto it: perms)
    {
        for (auto x: it) cout<<x<<' ';
        cout<<endl;
    }*/

    //cout<<perms.size();

    for (auto prm: perms)
    {
        vector<string> kek(h);
        for (int i = 0; i<h; i++) kek[i] = a[prm[i]];

        vector<string> kek1(w);
        for (int i = 0; i<h; i++)
        {
            for (int j = 0; j<w; j++) kek1[j]+=kek[i][j];
        }
        if (check(kek1)) {

            //for (auto it: kek1) cout<<it<<endl;

            cout<<"YES"; return 0;

        }
    }
    cout<<"NO";


}


Measured memory_bytes: 5072