#include <bits/stdc++.h>
#define REP(i, a, n) for(ll i = ((ll) a); i < ((ll) n); i++)
using namespace std;
typedef long long ll;

ll H, W;
vector<string> S;

bool check() {
  vector<bool> ok(W, false);
  ll cnt = 0;
  REP(i, 0, W) if(!ok[i]) {
    REP(j, i + 1, W) if(!ok[j]) {
      bool f = true;
      REP(k, 0, H) f = f && S[k][i] == S[H - 1 - k][j];
      if(f) {
        ok[i] = ok[j] = true;
        cnt += 2;
        break;
      }
    }
  }

  if(W % 2 == 1) {
    bool x = true;
    REP(i, 0, W) if(!ok[i]) {
      REP(j, 0, H) x = x && S[j][i] == S[H - 1 - j][i];
    }
    return cnt == W - 1 && x;
  }
  return cnt == W;
}

bool dfs(ll l, ll r) {
  if(r - l <= 1) return check();

  bool ret = false;
  REP(i, l + 1, r) {
    swap(S[i], S[r - 1]);
    ret = dfs(l + 1, r - 1) || ret;
    swap(S[i], S[r - 1]);
  }
  return ret;
}

int main(void) {
  cin >> H >> W;
  S.resize(H);
  REP(i, 0, H) cin >> S[i];

  bool ans = false;
  REP(i, 0, H) {
    swap(S[H / 2], S[i]);
    ans = ans || dfs(0, H);
    swap(S[H / 2], S[i]);
  }
  cout << (ans ? "YES" : "NO") << endl;;
}
