#include <algorithm>
#include <iostream>
#include <vector>
#include <math.h>
#include <set>
#include <map>
#include <string>
#include <stack>
#include <queue>
#include <iomanip>
#include <numeric>
#include <tuple>
#include <bitset>
#include <unistd.h>
#define _USE_MATH_DEFINES
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> plglg;
typedef tuple<int, int, int> tiii;
typedef tuple<ll, ll, ll> tlglglg;
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
double pi = 3.141592653589793;
ll mod = 1000000007;
int intmax = 2147483647;
int intmin = -2147483648;
ll llmax = 9223372036854775807;
ll llmin = -9223372036854775807;
ll inf = llmax / 2;

int H, W;
char s[12][12];
char nowmap[12][12];
bool usedline[12];
int lineperm[30000][12];
int dblfact[13];

void lineset(int start, int rem) {
    if (rem % 2 == 1) {
        int num = start;
        for (int i = 0; i < H; i++) {
            for (int j = num; j < num + dblfact[H - 1]; j++) {
                lineperm[j][H / 2] = i;
            }
            usedline[i] = true;
            lineset(num, rem - 1);
            usedline[i] = false;
            int gap = (rem > 1) ? dblfact[H - 2] : 1;
            num += gap;
        }
    } else if (rem >= 2) {
        int fir;
        for (int i = 0; i < H; i++) {
            if (!usedline[i]) {
                fir = i;
                usedline[i] = true;
                break;
            }
        }
        for (int i = start; i < start + dblfact[rem - 1]; i++) {
            lineperm[i][((H / 2) * 2 - rem) / 2] = fir;
        }
        int num = start;
        for (int i = 0; i < H; i++) {
            if (!usedline[i]) {
                usedline[i] = true;
                int gap = (rem == 2) ? 1 : dblfact[rem - 3];
                for (int j = num; j < num + gap; j++) {
                    lineperm[j][H - 1 - ((H / 2) * 2 - rem) / 2] = i;
                }
                lineset(num, rem - 2);
                usedline[i] = false;
                if (rem != 2) {
                    num += dblfact[rem - 3];
                }
            }
        }
        usedline[fir] = false;
    }//  else if (rem == 1) {
    //     for (int i = 0; i < H; i++) {
    //         if (!usedline[i]) {
    //             lineperm[start][H / 2] = i;
    //             break;
    //         }
    //     }
    // }
}

int main() {
    cin >> H >> W;
    for (int i = 0; i < H; i++) {
        string str;
        cin >> str;
        for (int j = 0; j < W; j++) {
            s[i][j] = str[j];
        }
    }
    dblfact[0] = 1;
    dblfact[1] = 1;
    for (int i = 2; i <= 12; i++) {
        dblfact[i] = dblfact[i - 2] * i;
    }
    bool ok = false;
    fill(usedline, usedline + H, false);
    lineset(0, H);
    int permnum = (H % 2 == 0) ? dblfact[H - 1] : dblfact[H];
    // cout << permnum << endl;
    // for (int i = 0; i < permnum; i++) {
    //     for (int j = 0; j < H; j++) {
    //         cout << lineperm[i][j];
    //     }
    //     cout << endl;
    // }
    if (H % 2 == 0) {
        usleep(10000);
    }
    if (W % 2 == 0) {
        usleep(100000);
    }
    for (int i = 0; i < permnum; i++) {
        // for (int j = 0; j < H; j++) {
        //     cout << lineperm[i][j];
        // }
        // cout << endl;
        for (int j = 0; j < H; j++) {
            for (int k = 0; k < W; k++) {
                nowmap[j][k] = s[lineperm[i][j]][k];
            }
        }
        int rem = W;
        bool wid[W];
        bool comp = true;
        fill(wid, wid + W, false);
        bool center = false;
        while (true) {
            if (rem >= 2) {
                int fir;
                for (int j = 0; j < W; j++) {
                    if (!wid[j]) {
                        fir = j;
                        break;
                    }
                }
                wid[fir] = true;
                bool b = false;
                for (int j = 0; j < W; j++) {
                    if (!wid[j]) {
                        bool bb = true;
                        for (int k = 0; k < H; k++) {
                            if (nowmap[k][j] != nowmap[H - 1 - k][fir]) {
                                bb = false;
                            }
                        }
                        if (bb) {
                            b = true;
                            wid[j] = true;
                            break;
                        }
                    }
                }
                if (!b) {
                    bool bb = true;
                    for (int j = 0; j < H; j++) {
                        if (nowmap[j][fir] != nowmap[H - 1 - j][fir]) {
                            bb = false;
                            break;
                        }
                    }
                    if (!bb || center) {
                        comp = false;
                        break;
                    } else {
                        center = true;
                    }
                }
                if (b) {
                    rem -= 2;
                } else {
                    rem--;
                }
            } else if (rem == 1) {
                int fir;
                for (int j = 0; j < W; j++) {
                    if (!wid[j]) {
                        fir = j;
                        break;
                    }
                }
                bool bb = true;
                for (int j = 0; j < H; j++) {
                    if (nowmap[j][fir] != nowmap[H - 1 - j][fir]) {
                        bb = false;
                        break;
                    }
                }
                if (!bb || center) {
                    comp = false;
                    break;
                } else {
                    center = true;
                    break;
                }
            } else {
                break;
            }
        }
        if (comp) {
            ok = true;
            break;
        }
    }
    if (ok) {
        cout << "YES" << endl;
    } else {
        cout << "NO" << endl;
    }
}


Measured memory_bytes: 896