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