/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author aajisaka
 */

#include<bits/stdc++.h>

using namespace std;

void debug_out() { cerr << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cerr << " " << to_string(H);
  debug_out(T...);
}
#ifdef LOCAL
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) 42
#endif

#define SPEED ios_base::sync_with_stdio(false);cin.tie(nullptr)
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define all(v) v.begin(), v.end()
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

using ll = long long;
using ull = unsigned long long;
using P = pair<ll, ll>;

constexpr long double PI = 3.14159265358979323846264338327950288L;
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());

class ESymmetricGrid {
public:

    vector<string> s;
    vector<bool> used;
    int h, w;
    bool ret = false;

    bool check(vector<int>& v) {
      multiset<string> vs;

      for(auto& e: s) {
        string str;
        str.resize(w);
        int idx = 0;
        if (w%2 != 0) {
          str[w/2] = e[v[0]];
          idx++;
        }
        for(int j=0; j*2+1+idx<w; j++) {
          str[j] = e[v[j*2+idx]];
          str[w-1-j] = e[v[j*2+1+idx]];
        }
        //cerr << str << endl;
        vs.insert(str);
      }

      bool center = false;
      auto it = vs.begin();
      while(it != vs.end()) {
        string now = (*it);
        string nowr = now;
        reverse(all(nowr));
        it = vs.erase(it);

        if (it != vs.end()) {
          string next = (*it);
          if (nowr == next) {
            it = vs.erase(it);
            continue;
          }
        }

        if (vs.find(nowr) != vs.end()) {
          vs.erase(vs.find(nowr));
          //cerr << nowr << endl;
          continue;
        }

        if (h%2 == 0) {
          return false;
        }

        if (!center && now == nowr) {
          center = true;
          continue;
        } else {
          return false;
        }
      }
      return true;
    }

    void dfs(vector<int>& v) {
      if (v.size() == w) {
        if (check(v)) ret = true;
        return;
      }

      for(int i=0; i<w; i++) {
        if (used[i]) continue;
        v.push_back(i);
        used[i] = true;
        dfs(v);
        used[i] = false;
        v.pop_back();
        // one of the pair can be defined.
        // the other is selected from all.
        if (w%2 != 0) {
          if (v.size()%2 != 0) break;
        } else {
          if (v.size()%2 == 0) break;
        }
      }
    }

    void solve(istream& cin, ostream& cout) {
      SPEED;
      cin >> h >> w;
      s.resize(h);
      rep(i, h) {
        cin >> s[i];
      }
      used.resize(w);
      vector<int> v;
      dfs(v);
      cout << (ret ? "YES" : "NO") << endl;
    }
};

signed main() {
  ESymmetricGrid solver;
  std::istream& in(std::cin);
  std::ostream& out(std::cout);
  solver.solve(in, out);
  return 0;
}

Measured memory_bytes: 3668