#include <bits/stdc++.h>
using namespace std;
int main() {
  int m, n;
  cin >> n >> m;
  string flag[n];
  char color, prev;
  getline(cin, flag[0]);
  for (int i = 0; i < n; i++) {
    getline(cin, flag[i]);
    color = flag[i][0];
    for (int j = 0; j < m; j++) {
      if ((char)flag[i][j] != color) return cout << "NO", 0;
    }
    if (i == 0)
      prev = color;
    else if (prev == color)
      return cout << "NO", 0;
    else
      prev = color;
  }
  cout << "YES";
  return 0;
}
