#include <bits/stdc++.h>
using namespace std;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int n, m;
  cin >> n >> m;
  vector<string> v(n);
  cin >> v[0];
  for (int i = 1; i < n; i++) {
    cin >> v[i];
    if (v[i] == v[i - 1]) {
      cout << "NO\n";
      return 0;
    }
  }
  for (int i = 0; i < n; i++) {
    for (int j = 1; j < m; j++) {
      string s = v[i];
      if (s[j] != s[j - 1]) {
        cout << "NO\n";
        return 0;
      }
    }
  }
  cout << "YES\n";
  return 0;
}
