#include <bits/stdc++.h>
using namespace std;
int main() {
  bool flag = true;
  char prevcolor = 'A';
  int n, m;
  cin >> n >> m;
  string s;
  while (n--) {
    cin >> s;
    if (s[0] == prevcolor) flag = false;
    if (flag)
      for (int i = 1; s[i]; i++) {
        if (s[i] != s[0]) {
          flag = false;
          break;
        }
      }
    prevcolor = s[0];
  }
  flag ? cout << "YES\n" : cout << "NO\n";
}
