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