#include <bits/stdc++.h>
using namespace std;
char flag[100][100];
int main(int argc, char *argv[]) {
  ios::sync_with_stdio(false);
  int n, m;
  int i, j;
  cin >> n >> m;
  for (i = 0; i < n; i++) {
    for (j = 0; j < m; j++) {
      cin >> flag[i][j];
    }
  }
  for (i = 0; i < n; i++) {
    for (j = 0; j < m - 1; j++) {
      if (flag[i][j] != flag[i][j + 1]) {
        cout << "NO" << endl;
        return 0;
      }
    }
    if (i < n - 1 && flag[i][0] == flag[i + 1][0]) {
      cout << "NO" << endl;
      return 0;
    }
  }
  cout << "YES" << endl;
  return 0;
}
