#include <bits/stdc++.h>

#define MAX_N 20

using namespace std;

int a[13][13];

int n, m;

string s;

vector <int> g[MAX_N + 1];

int ap[13][30];


int cuplajulDreapta[14];
int cuplajulStanga[14];

bool cuplaj[14];
//bool

bool cuplat(int n)
{
    if(cuplaj[n] == 1)
        return 0;

    cuplaj[n] = 1;

    int p;

    ///Cuplam nodul n cu primul vecin NEcuplat
    for(auto u : g[n])
    {
        if(cuplajulStanga[u] == 0 && cuplajulDreapta[u] == 0)
        {
            cuplaj[u] = 1;

            cuplajulDreapta[n] = u;
            cuplajulStanga[n] = u;

            cuplajulDreapta[u] = n;
            cuplajulStanga[u] = n;

            return 1;
        }
    }

    ///Nu am reusit, incercam sa refacem cuplajul vecinului pentru al cupla cu el
    for(auto u : g[n])
    {
        ///Daca putem recupla pe vecin
        if(cuplat(cuplajulStanga[u]) == 1)
        {
            cuplaj[u] = 1;

            cuplajulDreapta[n] = u;
            cuplajulStanga[n] = u;

            cuplajulDreapta[u] = n;
            cuplajulStanga[u] = n;

            return 1;
        }
    }

    return 0;
}

int lin[13];
int col[13];

bool solve(int n, int lin[])
{
    memset(cuplajulDreapta, 0, sizeof(cuplajulDreapta));
    memset(cuplajulStanga, 0, sizeof(cuplajulStanga));

    int i;

    int change = 1;
    int x;

    int rez = 0;
    while(change != 0)
    {
        change = 0;
        memset(cuplaj, 0, sizeof(cuplaj));

        for(i = 1; i <= n; i ++)
            if(cuplajulDreapta[i] == 0)
            {
                x = cuplat(i);

                change = change || x;
            }
    }

    int cr = 0;
    for(i = 1; i <= n; i ++)
    {
        if(cuplajulDreapta[i] != 0)
        {
            if(cuplajulDreapta[cuplajulDreapta[i]] != i || cuplajulStanga[cuplajulDreapta[i]] != i || cuplajulStanga[i] != cuplajulDreapta[i])
                assert(1 == 0);

            if(lin[i] == 0)
            {
                lin[i] = (++ cr);
                lin[cuplajulDreapta[i]] = n - lin[i] + 1;
            }

            rez ++;
        }
    }

    for(i = 1; i <= n; i ++)
    {
        g[i].clear();
        for(int j = 0; j <= 25; j ++)
            ap[i][j] = 0;
    }

//    cout << rez << " " << n <<"\n";

    if(n % 2 && rez == n - 1)
        rez ++;

    return (rez == n);
}

bool el()
{
    int i, h;
    for(i = 1; i <= n; i ++)
    {
        g[i].clear();
        for(h = 0; h <= 25; h ++)
            ap[i][h] = 0;
    }

    int j;
    for(i = 1; i <= n; i ++)
    {
        for(j = 1; j <= m; j ++)
            ap[i][a[i][j]] ++;
    }

    for(i = 1; i <= n; i ++)
    {
        for(j = i + 1; j <= n; j ++)
        {
            int ok = 1;
            for(h = 0; h <= 25; h ++)
                ok = ok && (ap[i][h] == ap[j][h]);

            if(ok)
            {
              //  cout << "LIN " << i << " " << j << "\n";
              //  g[j].push_back(i);
                g[i].push_back(j);
            }
        }
    }

    return solve(n, lin);
}

bool ec()
{
    int i, h;
    for(i = 1; i <= m; i ++)
    {
        g[i].clear();
        for(h = 0; h <= 25; h ++)
            ap[i][h] = 0;
    }

    int  j;
    for(i = 1; i <= m; i ++)
    {
        for(j = 1; j <= n; j ++)
            ap[i][a[j][i]] ++;
    }

    for(i = 1; i <= m; i ++)
    {
        for(j = i + 1; j <= m; j ++)
        {
            int ok = 1;
            for(h = 0; h <= 25; h ++)
                ok = ok && (ap[i][h] == ap[j][h]);

            if(ok)
            {
            //    cout << "COL " << i << " " << j << "\n";
            //    g[j].push_back(i);
                g[i].push_back(j);
            }
        }
    }

    return solve(m, col);
}

int b[13][13];

bool verif()
{
    int i, j;
    for(i = 1; i <= n; i ++)
    {
        for(j = 1; j <= m; j ++)
            b[lin[i]][col[j]] = a[i][j];

    }


    int rez = 1;
    for(i = 1; i <= n - i + 1; i ++)
    {
        for(j = 1; j <= m - j + 1; j ++)
        {
            rez = rez && (b[i][j] == b[n - i + 1][m - j + 1]);
        }
    }

    return rez;
}

int main()
{
    cin >> n >> m;

    int i, j;
    for(i = 1; i <= n; i ++)
    {
        cin >> s;
        for(j = 1; j <= m; j ++)
            a[i][j] = s[j - 1] - 'a';
    }

    int rez = el();
    rez += ec();
    rez += verif();

    cout << (rez == 3 ? "YES\n" : "NO\n");

    return 0;
}


Measured memory_bytes: 256