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