#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  cin >> n >> m;
  char l = 'm';
  bool res = 1;
  for (int i = 0; i < n; i++) {
    string x;
    cin >> x;
    char f = x[0];
    for (char t : x) {
      if (t != f) res = 0;
    }
    if (l == f) res = 0;
    l = f;
  }
  puts(res ? "YES" : "NO");
}
