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