#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m, k = 0;
  cin >> n >> m;
  int a[n + 10];
  for (int i = 1; i <= n; i++) {
    string s;
    cin >> s;
    set<char> v;
    for (int j = 0; j < s.size(); j++) v.insert(s[j]);
    if (v.size() != 1) {
      k++;
    }
    a[i] = s[0];
  }
  if (k > 0) {
    cout << "NO";
    return 0;
  }
  for (int i = 1; i < n; i++) {
    if (a[i] == a[i + 1]) {
      cout << "NO";
      return 0;
    }
  }
  cout << "YES";
}
