#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <queue>
#include <iomanip>
#include <bitset>
#include <cassert>
#include <cmath>
#include <cstring>
#include <climits>

using namespace std;

#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define REP(i, n) FOR(i, 0, n)
#define SORT(c) sort((c).begin(), (c).end())

typedef long long ll;
typedef pair<int, int> P;
typedef vector<int> V;
typedef map<int, int> M;

constexpr ll INF = 1e18;
constexpr ll MOD = 1e9 + 7;
constexpr double PI = 3.14159265358979323846;
constexpr int di[] = {0, 0, 1, -1};
constexpr int dj[] = {1, -1, 0, 0};

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);

    const string Yes = "YES";
    const string No = "NO";

    int h, w;
    string s[15];

    cin >> h >> w;

    REP(i, h)
    cin >> s[i];

    bool used[15];
    fill(used, used + w, false);

    int one = 0;

    REP(i, h)
    {
        if (used[i])
            continue;

        used[i] = true;

        int alp[30];
        fill(alp, alp + 26, 0);

        REP(j, s[i].size())
        alp[s[i][j] - 'a']++;

        V inds;

        for (int j = i + 1; j < h; j++)
        {
            int alp_[30];
            fill(alp_, alp_ + 26, 0);

            REP(k, w)
            alp_[s[j][k] - 'a']++;

            bool ok = true;
            REP(k, 26)
            if (alp[k] != alp_[k])
                ok = false;

            if (ok)
                inds.push_back(j);
        }

        int ind = i;

        for (int j : inds)
        {
            bool us[15];
            fill(us, us + w + 1, false);

            bool ok = true;

            for (int k = 0; k < w; k++)
            {
                if (us[k])
                    continue;

                us[k] = true;

                if (w % 2 && s[i][k] == s[j][k])
                    continue;

                bool update = false;

                for (int l = 0; l < w; l++)
                {
                    if (k == l)
                        continue;
                    if (s[i][k] == s[j][l] && s[i][l] == s[j][k])
                    {
                        us[l] = true;
                        update = true;
                        break;
                    }
                }

                if (!update)
                {
                    ok = false;
                    break;
                }
            }

            if (ok)
            {
                ind = j;
                break;
            }
        }

        if (ind == i)
            one++;

        used[ind] = true;
    }

    int cnt = 0;
    REP(i, h)
    cnt += used[i];

    if (cnt != h || one != h % 2)
    {
        cout << No << endl;
        return 0;
    }

    //#########################################

    string t[30];

    REP(i, w)
    {
        t[i] = "";
        REP(j, h)
        t[i] = t[i] + s[j][i];
    }

    fill(used, used + h, false);

    one = 0;

    REP(i, w)
    {
        if (used[i])
            continue;

        used[i] = true;

        int alp[30];
        fill(alp, alp + 26, 0);

        REP(j, h)
        alp[t[i][j] - 'a']++;

        V inds;

        for (int j = i + 1; j < w; j++)
        {
            int alp_[30];
            fill(alp_, alp_ + 26, 0);

            REP(k, h)
            alp_[t[j][k] - 'a']++;

            bool ok = true;
            REP(k, 26)
            if (alp[k] != alp_[k])
                ok = false;

            if (ok)
                inds.push_back(j);
        }

        int ind = i;

        for (int j : inds)
        {
            bool us[15];
            fill(us, us + h + 1, false);

            bool ok = true;

            for (int k = 0; k < h; k++)
            {
                if (us[k])
                    continue;

                us[k] = true;

                if (h % 2 && t[i][k] == t[j][k])
                    continue;

                bool update = false;

                for (int l = 0; l < h; l++)
                {
                    if (k == l)
                        continue;
                    if (t[i][k] == t[j][l] && t[i][l] == t[j][k])
                    {
                        us[l] = true;
                        update = true;
                        break;
                    }
                }

                if (!update)
                {
                    ok = false;
                    break;
                }
            }

            if (ok)
            {
                ind = j;
                break;
            }
        }

        if (ind == i)
            one++;

        used[ind] = true;
    }

    cnt = 0;
    REP(i, w)
    cnt += used[i];

    if (cnt != w || one != w % 2)
    {
        cout << No << endl;
        return 0;
    }

    cout << Yes << endl;

    return 0;
}

Measured memory_bytes: 256