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