#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m, i;
  vector<string> flag;
  string str;
  cin >> n >> m;
  for (i = 0; i < n; i++) cin >> str, flag.push_back(str);
  for (i = 0; i < n; i++) {
    if (i != 0) {
      if (flag[i][0] == flag[i - 1][0]) break;
    }
    if (i != n - 1) {
      if (flag[i][0] == flag[i + 1][0]) break;
    }
    if (flag[i].find_first_not_of(flag[i][0], 1) != string::npos) break;
  }
  cout << (i == n ? "YES" : "NO") << endl;
  return 0;
}
