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