#include <bits/stdc++.h>
using namespace std;
signed main() {
  long long n, m;
  cin >> n >> m;
  string grid[n];
  for (string& s : grid) {
    cin >> s;
    if (s != string(m, s[0])) {
      cout << "No\n";
      return 0;
    }
  }
  for (long long i = 1; i < n; i++) {
    if (grid[i][0] == grid[i - 1][0]) {
      cout << "No\n";
      return 0;
    }
  }
  cout << "YES\n";
}
