#include <bits/stdc++.h>
using namespace std;
int n, m, i, j;
char cad[1000][1000];
bool marcas[10];
int main() {
  bool ok = 1;
  scanf("%d%d", &n, &m);
  for (i = 0; i < n && ok; i++) {
    scanf("%s", cad[i]);
    for (j = 1; j < m && ok; j++) ok = cad[i][j] == cad[i][0];
  }
  for (i = 1; i < n && ok; i++)
    for (j = 0; j < m && ok; j++) ok = cad[i][j] != cad[i - 1][j];
  printf(ok ? "YES\n" : "NO\n");
  return 0;
}
