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