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