#include <bits/stdc++.h>
using namespace std;
int a[105][105];
int main(void) {
  int m, n;
  bool flag = true;
  cin >> n >> m;
  for (int i = 1; i <= n; ++i) {
    for (int j = 1; j <= m; ++j) {
      scanf("%1d", &a[i][j]);
    }
  }
  for (int i = 1; i <= n; ++i) {
    for (int j = 2; j <= m; ++j) {
      if (a[i][j] != a[i][1]) {
        flag = false;
        goto pdc;
      }
    }
  }
  for (int i = 2; i <= n; ++i) {
    if (a[i][1] == a[i - 1][1]) {
      flag = false;
      goto pdc;
    }
  }
pdc:
  if (flag) {
    cout << "YES" << endl;
  } else {
    cout << "NO" << endl;
  }
  return 0;
}
