#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m, b = 0;
  while (cin >> n >> m) {
    char a[m], c;
    for (int i = 0; i < n; i++) {
      cin >> a;
      if (a[0] == c) b++;
      c = a[0];
      for (int j = 1; j < m; j++)
        if (a[j] != c) b++;
    }
    if (b)
      cout << "NO" << endl;
    else
      cout << "YES" << endl;
  }
  return 0;
}
