#include <bits/stdc++.h>
using namespace std;
bool IO_FILE = 0;
ifstream ifs("input.txt");
ofstream ofs("output.txt");
int main() {
  if (IO_FILE) {
    cin.rdbuf(ifs.rdbuf());
    cout.rdbuf(ofs.rdbuf());
  }
  int n, m;
  cin >> n >> m;
  char *s = new char[m];
  bool res = 1;
  char prev = 'E';
  for (int i = 0; i < n; i++) {
    cin >> s;
    char p = s[0];
    res = 1;
    if (prev != 'E' && p == prev) {
      res = 0;
      break;
    }
    for (int j = 1; j < m; j++)
      if (!(res = s[j] == p)) break;
    if (!res) break;
    prev = p;
  }
  cout << (res ? "YES" : "NO");
}
