#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m, a = 0, b = 0;
  string s;
  cin >> n >> m;
  int arr[n];
  for (int i = 0; i < n; i++) {
    cin >> s;
    arr[i] = s[0];
    for (int j = 0; j < m - 1; j++) {
      if (s[j] == s[j + 1]) {
        a++;
      }
    }
  }
  for (int k = 0; k < n; k++) {
    if (arr[k] == arr[k + 1]) {
      b++;
    }
  }
  if (a == (m - 1) * n && b == 0) {
    cout << "YES" << endl;
  } else {
    cout << "NO" << endl;
  }
  return 0;
}
