#include <bits/stdc++.h>
using namespace std;
string a[104];
int main() {
  int n, m;
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= n; i++) cin >> a[i];
  bool f = true;
  char x, fi, qi = '@';
  for (int i = 1; i <= n; i++) {
    fi = a[i][0];
    if (fi == qi) {
      f = false;
      break;
    } else
      qi = fi;
    for (int j = 1; j < m; j++) {
      x = a[i][j];
      if (x != fi) {
        f = false;
        break;
      }
    }
    if (!f) break;
  }
  if (!f)
    printf("NO");
  else
    printf("YES");
  return 0;
}
