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