#include <bits/stdc++.h>
using namespace std;
char flag[105][105];
int main() {
  int n, m;
  cin >> n >> m;
  for (int row = 0; row < n; row++) {
    for (int col = 0; col < m; col++) {
      cin >> flag[row][col];
    }
  }
  bool isyes = true;
  for (int row = 0; row < n && isyes == true; row++) {
    char current_color = flag[row][0];
    bool ok = true;
    for (int col = 0; col < m; col++) {
      if (flag[row][col] != current_color) {
        ok = false;
        isyes = false;
        break;
      }
    }
  }
  if (isyes == false) {
    cout << "NO" << endl;
  } else {
    for (int row = 0; row < n - 1; row++) {
      if (flag[row][0] == flag[row + 1][0]) {
        isyes = false;
        break;
      }
    }
    if (isyes == true) {
      cout << "YES" << endl;
    } else {
      cout << "NO" << endl;
    }
  }
  return 0;
}
