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