#include <bits/stdc++.h>
using namespace std;
int n, m;
char s[105][105];
int main() {
  int i, j, a, b, c = 0;
  scanf("%d %d", &n, &m);
  getchar();
  for (i = 0; i < n; i++) {
    scanf("%s", s[i]);
  }
  for (i = 0; i < n && !c; i++) {
    a = b = 0;
    for (j = 1; j < m; j++) {
      if (s[i][j] != s[i][j - 1]) {
        a = 1;
        break;
      }
    }
    if (i > 0 && s[i][0] == s[i - 1][0]) b = 1;
    if (a + b > 0) c = 1;
  }
  if (!c)
    printf("YES\n");
  else
    printf("NO\n");
  return 0;
}
