#include <bits/stdc++.h>
using namespace std;
int main() {
  int n = 0;
  int m = 0;
  cin >> n;
  cin >> m;
  char arr[n][m];
  bool flag = true;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      cin >> arr[i][j];
    }
  }
  for (int i = 0; i < n && flag; i++) {
    if (i + 1 < n) {
      if (arr[i + 1][0] == arr[i][0]) {
        flag = false;
      }
    }
    for (int j = 0; j < m - 1 && flag; j++) {
      if (arr[i][j] != arr[i][j + 1]) {
        flag = false;
      }
    }
  }
  if (flag) {
    cout << "YES" << endl;
  } else {
    cout << "NO" << endl;
  }
  return 0;
}
