#include <bits/stdc++.h>
using namespace std;
int N, M;
char pc, c, x;
int main(int argc, const char* argv[]) {
  cin >> N >> M;
  pc = '.';
  for (int n = 0; n < N; n++) {
    cin >> c;
    if (c == pc) {
      cout << "NO" << endl;
      return 0;
    }
    for (int m = 1; m < M; m++) {
      cin >> x;
      if (x != c) {
        cout << "NO" << endl;
        return 0;
      }
    }
    pc = c;
  }
  cout << "YES" << endl;
  return 0;
}
