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