#include <bits/stdc++.h>
using namespace std;
string str[110];
int n, m;
bool hang(int a) {
  for (int i = 1; i < m; i++) {
    if (str[a][i] != str[a][i - 1]) return false;
  }
  return true;
}
int main() {
  cin >> n >> m;
  for (int i = 1; i <= n; i++) cin >> str[i];
  if (!hang(1)) {
    cout << "NO";
    return 0;
  }
  for (int i = 2; i <= n; i++) {
    if (!hang(i)) {
      cout << "NO";
      return 0;
    }
    if (str[i] == str[i - 1]) {
      cout << "NO";
      return 0;
    }
  }
  cout << "YES";
  return 0;
}
