#include <bits/stdc++.h>
using namespace std;
void input() {
  int i, nh, nc, j;
  char s[105][105];
  scanf("%d %d", &nh, &nc);
  for ((i) = 0; (i) < (nh); (i)++) scanf("%s", &s[i]);
  for ((i) = 0; (i) < (nh); (i)++) {
    for ((j) = 0; (j) < (nc); (j)++)
      if (s[i][j] != s[i][0]) {
        printf("NO");
        return;
      }
    if (i && s[i][0] == s[i - 1][0]) {
      printf("NO");
      return;
    }
  }
  printf("YES");
}
int main() {
  input();
  return 0;
}
