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