#include <bits/stdc++.h>
using namespace std;
int main(int argc, char *argv[]) {
  int n, m;
  string s;
  vector<string> v;
  bool notEqual = false;
  bool equal = false;
  cin >> n >> m;
  for (int i = 0; i < n; i++) {
    cin >> s;
    v.push_back(s);
  }
  for (int i = 0; i < n; i++) {
    for (int j = 1; j < m; j++) {
      if (v[i][0] != v[i][j]) notEqual = true;
    }
  }
  if (notEqual)
    cout << "NO" << endl;
  else {
    for (int i = 0; i < n - 1; i++) {
      if (v[i] == v[i + 1]) equal = true;
    }
    if (equal)
      cout << "NO" << endl;
    else
      cout << "YES" << endl;
  }
}
