#include <bits/stdc++.h>
using namespace std;
int n, m;
bool issame(string in) {
  bool flag = true;
  for (int j = 0; j < m - 1; j++) {
    if (in[j] != in[j + 1]) {
      flag = false;
      break;
    }
  }
  return flag;
}
bool isdiff(string in) {
  bool flag = true;
  for (int j = 0; j < n - 1; j++) {
    if (in[j] == in[j + 1]) {
      flag = false;
      break;
    }
  }
  return flag;
}
int main() {
  cin >> n >> m;
  string input[n];
  for (int i = 0; i < n; i++) {
    cin >> input[i];
  }
  bool result = true;
  for (int i = 0; i < n; i++) {
    if (!issame(input[i])) {
      result = false;
      break;
    }
  }
  string test = "";
  for (int i = 0; i < n && result; i++) {
    test += input[i][0];
  }
  if (!isdiff(test) && result) result = false;
  if (result)
    cout << "YES" << endl;
  else
    cout << "NO" << endl;
  return 0;
}
