#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m, c = 0;
  cin >> n >> m;
  string s[n];
  for (int i = 0; i < n; i++) {
    cin >> s[i];
    for (int j = 0; j < m - 1; j++) {
      if (s[i].at(j) != s[i].at(j + 1)) {
        c++;
      }
    }
  }
  if (c != 0) {
    cout << "NO";
  } else {
    int d = 0;
    for (int i = 0; i < n - 1; i++) {
      if (s[i].at(0) == s[i + 1].at(0)) {
        d++;
      }
    }
    if (d != 0) {
      cout << "NO";
    } else {
      cout << "YES";
    }
  }
  return 0;
}
