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