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