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