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