#ifdef DEBUG
#define _GLIBCXX_DEBUG
#endif
//#pragma GCC optimize("O3")
#include <bits/stdc++.h>
using namespace std;
typedef long double ld;
typedef long long ll;
int h, w;
const int maxN = 15;
char a[maxN][maxN];
vector < vector < int > > gen_perm(int h) {
    vector < int > to(h, -1);
    vector < vector < int > > ans;
    ans.emplace_back(to);
    for (int i = 0; i < h; i++) {
        vector < vector < int > > nans;
        for (auto& vec : ans) {
            if (vec[i] != -1) {
                nans.emplace_back(vec);
                continue;
            }
            bool has = false;
            for (int r = 0; r < h; r++) {
                if (vec[r] == r) {
                    has = true;
                    break;
                }
            }
            if (h % 2 == 0) {
                assert(!has);
                for (int c = i + 1; c < h; c++) {
                    if (vec[c] != -1) continue;
                    auto nvec = vec;
                    nvec[i] = c;
                    nvec[c] = i;
                    nans.emplace_back(nvec);
                }
            }
            else {
                for (int c = i; c < h; c++) {
                    if (vec[c] != -1) continue;
                    if (c == i && has) continue;
                    auto nvec = vec;
                    nvec[i] = c;
                    nvec[c] = i;
                    nans.emplace_back(nvec);
                }
            }
        }
        ans = nans;
    }
    return ans;
}
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
//    freopen("input.txt", "r", stdin);
    cin >> h >> w;
    auto p1 = gen_perm(h);
    auto p2 = gen_perm(w);
//    for (auto& it : p1) {
//        for (int v : it) {
//            cout << v << " ";
//        }
//        cout << endl;
//    }
//    cout << "=====" << endl;
    for (int i = 0; i < h; i++) {
        for (int j = 0; j < w; j++) {
            cin >> a[i][j];
        }
    }
    for (auto& row_perm : p1) {
        bool can = true;
        for (int i = 0; i < h; i++) {
            vector < char > gg1, gg2;
            for (int j = 0; j < w; j++) {
                gg1.emplace_back(a[i][j]);
                gg2.emplace_back(a[row_perm[i]][j]);
            }
            sort(gg1.begin(), gg1.end());
            sort(gg2.begin(), gg2.end());
            if (gg1 != gg2) {
                can = false;
                break;
            }
            else {
//                if (i != row_perm[i]) {
//                    cout << " HITHERE " << i << " " << row_perm[i] << endl;
//                }
            }
        }
        if (!can) {
            continue;
        }
        for (auto& col_perm : p2) {
            bool ok = true;
            for (int i = 0; i < h; i++) {
                for (int j = 0; j < w; j++) {
                    if (a[row_perm[i]][col_perm[j]] != a[i][j]) {
                        ok = false;
                        break;
                    }
                }
            }
            if (ok) {
//                for (int u : row_perm) cout << u << " ";
//                cout << endl;
//                for (int t : col_perm) cout << t << " ";
//                cout << endl;
                cout << "YES\n";
                return 0;
            }
        }
    }
    cout << "NO\n";
    return 0;
}

Measured memory_bytes: 6964