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