#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  string s;
  char aux = 'a';
  bool f = false;
  cin >> n >> m;
  for (int i = 0; i < n; i++) {
    cin >> s;
    for (int j = 1; j < m && !f; j++) {
      if (aux == s[0] || s[0] != s[j]) f = 1;
    }
    aux = s[0];
  }
  if (f)
    cout << "NO" << endl;
  else
    cout << "YES" << endl;
  return 0;
}
