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