#define STOPIT
#include <bits/stdc++.h>
#define loop(n) for (lint ngtkana_is_a_genius = 0; ngtkana_is_a_genius < lint(n); ngtkana_is_a_genius++)
#define rep(i, begin, end) for (lint i = lint(begin); (i) < lint(end); i++)
#define all(v) v.begin(), v.end()
#define rand(l, r) std::uniform_int_distribution<>(l, r)(mt)
using lint = long long;
auto mt = std::mt19937_64(std::random_device{}());
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...); }
#ifndef STOPIT
#define debug(...)\
  do {\
    std::cerr << std::boolalpha << "[" << #__VA_ARGS__ << "]:";\
    debug_impl(__VA_ARGS__);\
    std::cerr << std::noboolalpha;\
  } while (false)
#else
#define debug(...) {}
#endif

template < typename Container, typename Value = typename Container::value_type, std::enable_if_t<!std::is_same< Container, std::string >::value, std::nullptr_t> = nullptr>
std::istream& operator>> (std::istream& is, Container& v)
  { for (auto & x : v) { is >> x; } return is; }

template < typename Container, typename Value = typename Container::value_type, std::enable_if_t<!std::is_same< Container, std::string >::value, std::nullptr_t> = nullptr >
std::ostream& operator<< (std::ostream& os, Container const& v) {
 os << "{";
  for (auto it = v.begin(); it != v.end(); it++)
    {os << (it != v.begin() ? "," : "") << *it;}
  return os << "}";
}

template < template < typename ... > class Tuple,  typename... Args, std::size_t ... Inds, std::size_t = std::tuple_size< Tuple < Args ... > >::value >
std::istream& tuple_input_impl(std::istream& os, Tuple<Args...>& tuple, std::integer_sequence<std::size_t, Inds...>)
  { (void)std::initializer_list<int>{((void)(os >> std::get< Inds >(tuple)), 0)...}; return os; }
template < template < typename ... > class Tuple,  typename... Args, std::size_t = std::tuple_size< Tuple < Args ... > >::value >
std::istream& operator>> (std::istream& os, Tuple<Args...>& tuple)
  { return tuple_input_impl(os, tuple, std::index_sequence_for<Args...>()); }

template < template < typename ... > class Tuple,  typename... Args, std::size_t ... Inds, std::size_t = std::tuple_size< Tuple < Args ... > >::value >
std::ostream& tuple_output_impl(std::ostream& os, const Tuple<Args...>& tuple, std::integer_sequence<std::size_t, Inds...>)
  { os << "("; (void)std::initializer_list<int>{((void)(os << (Inds > 0 ? "," : "") << std::get< Inds >(tuple)), 0)...}; return os << ")"; }
template < template < typename ... > class Tuple,  typename... Args, std::size_t = std::tuple_size< Tuple < Args ... > >::value >
std::ostream& operator<< (std::ostream& os, const Tuple<Args...>& tuple)
 { return tuple_output_impl(os, tuple, std::index_sequence_for<Args...>()); }

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...);}

template < typename Value >
auto transpose(std::vector< std::vector< Value > > const& grid) {
  int h = grid.size();
  int w = grid.front().size();
  auto ret = std::vector< std::vector< Value > > (w, std::vector< Value >(h));
  for (auto i = 0; i < h; i++) {
    for(auto j = 0; j < w; j++) {
      ret.at(j).at(i) = grid.at(i).at(j);
    }
  }
  return ret;
}

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

  auto make_index_pairs = [&] (int W) {
    int n = W / 2;
    int N = 2 * n;
    std::vector<std::vector<std::pair<int,int>>> ans;
    std::vector<std::pair<int,int>> now;
    std::vector<int> ckd(W,false);
    auto dfs = [&] (auto&& dfs) -> void {
      if ((int)now.size() == n) {
        ans.emplace_back(now);
        return;
      }

      int i = std::find(all(ckd), false) - ckd.begin();
      assert(0 <= i && i < W);
      ckd.at(i) = true;

      rep(j,0,W) {
        if (ckd.at(j)) continue;
        ckd.at(j) = true;
        now.emplace_back(i,j);
        dfs(dfs);
        ckd.at(j) = false;
        now.pop_back();
      }
      ckd.at(i) = false;
    };
    if (N==W) {
      dfs(dfs);
    } else {
      rep(i,0,W) {
        ckd.at(i) = true;
        dfs(dfs);
        ckd.at(i) = false;
      }
    }
    return ans;
  };

  int h, w; std::cin >> h >> w;
  auto grid = make_vector<2,char>(h,w);
  rep(i,0,h) rep(j,0,w) {
    char c; std::cin >> c;
    at(grid,i,j) = c;
  }
  auto index_pairs = make_index_pairs(w);
  debug(h,w,grid,index_pairs.size(),index_pairs);

  auto cal = [&] (auto grid, auto&& index_pair) {
    // #ifndef STOPIT
    //   for (auto&& v : grid) {
    //     debug(v);
    //   }
    //   debug("||");
    // #endif

    int center = -1;
    if (w%2==1) {
      std::vector<int> ckd(w,false);
      for (auto&& p : index_pair) {
        ckd.at(p.first) = true;
        ckd.at(p.second) = true;
      }
      auto it = std::find(all(ckd), false);
      assert(it != ckd.end());
      center = it - ckd.begin();
    }

    int sz = index_pair.size();
    for (auto&& v : grid) {
      std::vector<char> new_v(w);
      rep(k,0,sz) {
        int i,j; std::tie(i,j) = index_pair.at(k);
        new_v.at(k) = v.at(i);
        new_v.at(w-1-k) = v.at(j);
      }
      if (w%2==1) {
        assert(center!=-1);
        new_v.at(w/2) = v.at(center);
      }
      new_v.swap(v);
    }

    #ifndef STOPIT
      for (auto&& v : grid) {
        debug(v);
      }
      debug(index_pair);
      debug("");
    #endif

    bool found = false;
    while (2u <= grid.size()) {
      auto v = grid.back(); grid.pop_back();
      std::reverse(all(v));
      auto it = std::find(all(grid), v);
      if (it == grid.end()) {
        if (!found && v==std::vector<char>(v.rbegin(),v.rend())) {
          found = true;
          continue;
        } else {
          return false;
        }
      }
      grid.erase(it);
    }
    if (grid.empty()) return true;
    assert(grid.size() == 1u);
    if (found) return false;
    auto v = grid.front();
    return v == std::vector<char>(v.rbegin(), v.rend());
  };

  for (auto&& v : index_pairs) {
    bool res = cal(grid,v);
    if (res) {
      std::cout << "YES" << std::endl;
      exit(0);
    }
  }
  std::cout << "NO" << std::endl;
  return 0;
}

/*
W 個を 2 個ずつのペアに分けるやり方を全探索です。
奇数なら孤立したものも全探索です。
これがきまったら、これに従って実際に文字を並び替えます。
これが済んだら、お互いに reverse の関係にあるものを消していって、何も残らなければ勝ちです。
*/

Measured memory_bytes: 1212