#include <bits/stdc++.h>
#define loop(n) for (int ngtkana_is_genius = 0; ngtkana_is_genius < int(n); ngtkana_is_genius++)
#define rep(i, begin, end) for(int i = int(begin); i < int(end); i++)
#define all(v) v.begin(), v.end()
#define lint long long
auto cmn = [](auto& a, auto b){if (a > b) {a = b; return true;} return false;};
auto cmx = [](auto& a, auto b){if (a < b) {a = b; return true;} return false;};
void debug_impl() { std::cerr << std::endl; }
template <typename Head, typename... Tail>
void debug_impl(Head head, Tail... tail){
  std::cerr << " " << head;
  debug_impl(tail...);
}
#define debug(...)\
  std::cerr << std::boolalpha << "[" << #__VA_ARGS__ << "]:";\
  debug_impl(__VA_ARGS__);\
  std::cerr << std::noboolalpha;

template <typename T, typename U>
std::ostream& operator<< (std::ostream& os, const std::pair<T, U>& pair)
  { return os << "(" << pair.first << "," << pair.second << ")"; }

template <typename T, typename U>
std::istream& operator>> (std::iostream& is, std::pair<T, U>& pair)
  { return is >> pair.first >> pair.second; }

template <typename T>
std::istream& operator>> (std::istream& is, std::vector<T>& v) {
  for (auto & x : v) is >> x;
  return is;
}

template <typename T>
std::ostream& operator<< (std::ostream& os, const std::vector<T>& v) {
  auto n = v.size();
  os << "{";
  for (size_t i = 0; i < n; i++)
    {os << (i > 0 ? "," : "") << v.at(i);}
  return os << "}";
}

template <typename T>
auto make_vector_impl(size_t sz, T t) {return std::vector<T>(sz, t);}

template <size_t N, typename T, typename U, std::enable_if_t<N == 1, std::nullptr_t> = nullptr>
auto make_vector(size_t sz, U u) {return make_vector_impl(sz, T(u));}

template <size_t N, typename T, std::enable_if_t<N == 1, std::nullptr_t> = nullptr>
auto make_vector(size_t sz) {return std::vector<T>(sz);}

template <size_t N, typename T, typename... Args, std::enable_if_t<N != 1, std::nullptr_t> = nullptr>
auto make_vector(size_t a, Args... args) {return make_vector_impl(a, make_vector<N - 1, T>(args...));}

template <typename T, typename Size_t>
auto& at(T& t, Size_t i) {return t.at(i);}

template <typename T, typename Size_t, typename... Args>
auto& at(T& t, Size_t i, Args... args) {return at(t.at(i), args...);}

int main() {
  std::cin.tie(0); std::cin.sync_with_stdio(false);
  int h, w; std::cin >> h >> w;
  std::vector< std::string > s(h);
  std::cin >> s;
  std::vector< int > mate(w, -1);
  auto reveq = [&] (auto&& a, auto&& b) {
    rep(j, 0, w) {
      if (a.at(j) != b.at(w - 1 - j))
        { return false; }
    }
    return true;
  };
  auto simulate = [&] {
    std::vector< int > ckd(w, false);
    std::vector< int > p(w, -1);
    auto found = false;
    rep(i, 0, w) {
      if (mate.at(i) == i) {
        p.at(w / 2) = i;
        ckd.at(i) = true;
        found = true;
        break;
      }
    }
    assert(w % 2 == found);
    auto pos = 0;
    rep(i, 0, w) {
      if (ckd.at(i)) continue;
      auto j = mate.at(i);
      assert(!ckd.at(j));
      ckd.at(i) = true;
      ckd.at(j) = true;
      p.at(pos) = i, p.at(w - 1 - pos) = j;
      pos++;
    }
    assert(pos * 2 + found == w);
    assert(std::all_of(all(ckd), [](auto x){ return x; }));

    auto t = s;
    rep(i, 0, h) rep(j, 0, w)
      { at(t, i, j) = at(s, i, p.at(j)); }
    auto allow_orphan = h % 2;
    std::vector< std::pair < std::string, std::string > > ret;
    while (!t.empty()) {
      auto a = t.back();
      auto found = false;
      for (auto it = t.begin(); it != t.end() - 1 && it != t.end(); it++) {
        if (reveq(a, *it)) {
          ret.emplace_back(a, *it);
          t.erase(it);
          t.pop_back();
          found = true;
          break;
        }
      }
      if (!found) {
        if (!allow_orphan || !reveq(a, a))
          { return false; }
        allow_orphan = false;
        ret.emplace_back(a, a);
        t.pop_back();
      }
    }
    // debug(ret);
    return true;
  };
  auto unite = [&](auto i, auto j){
    assert(mate.at(i) == -1 && mate.at(j) == -1);
    mate.at(i) = j;
    mate.at(j) = i;
  };
  auto separate = [&](auto i, auto j){
    assert(mate.at(i) != -1 && mate.at(j) != -1);
    mate.at(i) = -1;
    mate.at(j) = -1;
  };
  auto dfs = [&](auto&& f) -> void {
    auto i = 0;
    for (; i <= w; i++) {
      if (i == w) {
        if (simulate()) {
          std::cout << "YES" << std::endl;
          exit(0);
        }
        return;
      }
      if (mate.at(i) == -1)
        { break; }
    }
    auto found = false;
    rep(j, 0, w) {
      if (i != j && mate.at(j) == -1) {
        unite(i, j);
        f(f);
        separate(i, j);
        found = true;
      }
    }
  };
  if (w % 2 == 1) {
    rep(i, 0, w) {
      unite(i, i);
      dfs(dfs);
      separate(i, i);
    }
  } else {
    dfs(dfs);
  }
  std::cout << "NO" << std::endl;
  return 0;
}


Measured memory_bytes: 256