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