#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  long long n, m;
  cin >> n >> m;
  string p[111];
  for (long long i = 1; i <= n; i++) cin >> p[i];
  for (long long i = 2; i <= n; i++)
    if (p[i] == p[i - 1]) {
      cout << "NO";
      return 0;
    }
  for (long long i = 1; i <= n; i++)
    for (long long j = 1; j < p[i].size(); j++) {
      if (p[i][j] != p[i][j - 1]) {
        cout << "NO";
        return 0;
      }
    }
  cout << "YES";
  return 0;
}
