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