#include <bits/stdc++.h>
static void skip_whitespace(FILE *fp) {
  for (int k = fgetc(fp); isspace(k) || (ungetc(k, fp) && false); k = fgetc(fp))
    ;
}
int main(int argc, char *argv[]) {
  int n, m;
  if (fscanf(stdin, "%d %d", &n, &m) != 2) {
    fprintf(stderr, "fscanf: IO error.\n");
    exit(EXIT_FAILURE);
  }
  bool valid = true;
  for (int r = 0, s = -1; r < n && valid; r++) {
    skip_whitespace(stdin);
    for (int c = 0; c < m && valid; c++) {
      const int k = fgetc(stdin);
      valid =
          ('0' <= k && k <= '9') && ((c == 0 && s != k) || (c > 0 && s == k));
      s = (c == 0 ? k : s);
    }
  }
  printf(valid ? "YES\n" : "NO\n");
  return EXIT_SUCCESS;
}
