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