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