#include <bits/stdc++.h>
using namespace std;
int main() {
  set<int, greater<int> > s;
  int n, m;
  cin >> n;
  cin >> m;
  int arr[n];
  string str;
  bool flag = true;
  for (int i = 0; i < n; i++) {
    cin >> str;
    for (int j = 0; j < str.length(); j++) {
      s.insert(str[j]);
    }
    if (s.size() != 1) {
      flag = false;
      break;
    }
    arr[i] = *s.begin();
    s.erase(s.begin(), s.end());
  }
  for (int j = 0; j < n - 1; j++) {
    if (arr[j] == arr[j + 1]) {
      flag = false;
      break;
    }
  }
  if (flag) {
    cout << "YES";
  } else {
    cout << "NO";
  }
}
