#include <bits/stdc++.h>
using namespace std;
int main() {
  string st, arr[100];
  int n, m;
  cin >> n >> m;
  for (int i = 0; i < n; i++) {
    cin >> st;
    for (int j = 1; j < st.length(); j++) {
      if (st[j] != st[j - 1]) {
        cout << "NO" << endl;
        return 0;
      }
    }
    arr[i] = st;
  }
  for (int i = 0; i < n; i++) {
    if (arr[i] == arr[i + 1]) {
      cout << "NO" << endl;
      return 0;
    }
  }
  cout << "YES" << endl;
  return 0;
}
