#include <bits/stdc++.h>
using namespace std;
int main() {
  int RowSize, ColoumnSize;
  char Flag, FirstCharRow, FirstCharColomn = 'a';
  bool End = false;
  scanf("%d%d", &ColoumnSize, &RowSize);
  for (int Coloumn = 0; Coloumn < ColoumnSize; Coloumn++) {
    cin >> Flag;
    if (Flag == FirstCharColomn) {
      End = true;
      break;
    }
    FirstCharRow = Flag;
    for (int Row = 0; Row < RowSize - 1; Row++) {
      cin >> Flag;
      if (Flag != FirstCharRow) End = true;
    }
    if (End == true) break;
    FirstCharColomn = Flag;
  }
  if (!End)
    cout << "YES" << endl;
  else
    cout << "NO" << endl;
  return 0;
}
