#include <bits/stdc++.h>
using namespace std;
template <class T>
bool uin(T &a, T b) {
  return a > b ? (a = b, true) : false;
}
template <class T>
bool uax(T &a, T b) {
  return a < b ? (a = b, true) : false;
}
void solve() {
  int n, m;
  cin >> n >> m;
  char prev = 'a';
  vector<string> a(n);
  for (int i = 0; i < (int)(n); ++i) {
    cin >> a[i];
  }
  for (int i = 0; i < (int)(n); ++i) {
    if (prev == a[i][0]) {
      cout << "NO";
      return;
    }
    for (int j = 1; j < m; ++j) {
      if (a[i][j] != a[i][j - 1]) {
        cout << "NO";
        return;
      }
    }
    prev = a[i][0];
  }
  cout << "YES";
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  int t = 1;
  while (t--) {
    solve();
  }
}
