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