# include <bits/stdc++.h>
using namespace std;

const int N = 100005;
typedef long long i64;
const i64 INF = 1000000007;
typedef long long i64;

char s[15][15];
vector<char> v;
map<int, int> mp, exmp;
int row[15], col[15], per_1[15], per_2[15];
vector<int> A[30];

bool comp(char a, char b) {return a < b;}
int main ()
{
    int H, W;
    scanf("%d %d", &H, &W);
    for (int i = 1; i <= H; ++i) {
        scanf("%s", s[i] + 1);
        v.clear();
        for (int j = 1; j <= W; ++j) v.push_back(s[i][j]);
        sort(v.begin(), v.end(), comp);
        int hsh = 0;
        for (int j = 0; j < W; ++j) hsh = hsh * 31 + v[j];
        row[i] = hsh;
        ++mp[hsh];
    }
    for (int i = 1; i <= W; ++i) {
        v.clear();
        for (int j = 1; j <= H; ++j) v.push_back(s[j][i]);
        sort(v.begin(), v.end(), comp);
        int hsh = 0;
        for (int j = 0; j < H; ++j) hsh = hsh * 31 + v[j];
        col[i] = hsh;
        ++exmp[hsh];
    }
    int num = 0;
    for (auto i = mp.begin(); i != mp.end(); ++i) {
        if ((i->second) & 1) ++num;
    }
    if (H & 1) {
        if (num != 1) {puts("NO"); return 0;}
        else {
            int k = 1;
            for (auto i = mp.begin(); i != mp.end(); ++i) {
                for (int j = 1; j <= H; ++j) if (i->first == row[j]) A[k].push_back(j);
                ++k;
            }
            int now = 0;
            for (int i = 1; i <= k; ++i) {
                int j = 0;
                if (A[i].size() & 1) per_1[H / 2 + 1] = A[i][0], j = 1;
                for (; j < A[i].size(); j += 2) {
                    per_1[now + 1] = A[i][j];
                    per_1[H - now] = A[i][j + 1];
                    ++now;
                }
            }
        }
    }
    else {
        if (num) {puts("NO"); return 0;}
        else {
            int k = 1;
            for (auto i = mp.begin(); i != mp.end(); ++i) {
                for (int j = 1; j <= H; ++j) if (i->first == row[j]) A[k].push_back(j);
                ++k;
            }
            int now = 0;
            for (int i = 1; i <= k; ++i) {
                int j = 0;
                for (; j < A[i].size(); j += 2) {
                    per_1[now + 1] = A[i][j];
                    per_1[H - now] = A[i][j + 1];
                    ++now;
                }
            }
        }
    }
    num = 0;
    for (auto i = exmp.begin(); i != exmp.end(); ++i) {
        if ((i->second) & 1) ++num;
    }
    for (int i = 0; i < 15; ++i) A[i].clear();
    if (W & 1) {
        if (num != 1) {puts("NO"); return 0;}
        else {
            int k = 1;
            for (auto i = exmp.begin(); i != exmp.end(); ++i) {
                for (int j = 1; j <= W; ++j) if (i->first == col[j]) A[k].push_back(j);
                ++k;
            }
            int now = 0;
            for (int i = 1; i <= k; ++i) {
                int j = 0;
                if (A[i].size() & 1) per_2[W / 2 + 1] = A[i][0], j = 1;
                for (; j < A[i].size(); j += 2) {
                    per_2[now + 1] = A[i][j];
                    per_2[W - now] = A[i][j + 1];
                    ++now;
                }
            }
        }
    }
    else {
        if (num) {puts("NO"); return 0;}
        else {
            int k = 1;
            for (auto i = exmp.begin(); i != exmp.end(); ++i) {
                for (int j = 1; j <= W; ++j) if (i->first == col[j]) A[k].push_back(j);
                ++k;
            }
            int now = 0;
            for (int i = 1; i <= k; ++i) {
                int j = 0;
                for (; j < A[i].size(); j += 2) {
                    per_2[now + 1] = A[i][j];
                    per_2[W - now] = A[i][j + 1];
                    ++now;
                }
            }
        }
    }
//    for (int i = 1; i <= H; ++i) printf("%d ", per_1[i]);
//    puts("");
//    for (int i = 1; i <= W; ++i) printf("%d ", per_2[i]);
//    puts("");
    for (int i = 1; i <= H; ++i) for (int j = 1; j <= W; ++j) {
        if (s[per_1[i]][per_2[j]] != s[per_1[H + 1 - i]][per_2[W + 1 - j]]) {
            puts("NO");
            return 0;
        }
    }
    puts("YES");
    return 0;
}


Measured memory_bytes: 256