#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m, flag = 0, fl = 0;
  cin >> n >> m;
  char ch[n][m], cho[n];
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      cin >> ch[i][j];
      if (j != 0 && ch[i][j] != ch[i][j - 1]) {
        flag = 1;
        break;
      }
    }
    cho[i] = ch[i][0];
  }
  for (int i = 1; i < n; i++) {
    if (cho[i] == cho[i - 1]) {
      fl = 1;
    }
  }
  if (fl == 1 || flag == 1) {
    cout << "NO";
  } else {
    cout << "YES";
  }
  return 0;
}
