#include <bits/stdc++.h>
using namespace std;
int main() {
  int x, y;
  char m[100][100];
  cin >> x >> y;
  for (int i = 0; i < x; i++) {
    for (int k = 0; k < y; k++) {
      cin >> m[i][k];
    }
  }
  for (int i = 0; i < x - 1; i++) {
    for (int k = 0; k < y; k++) {
      if (m[i][k] != m[i][0] || m[i][0] == m[i + 1][0]) {
        cout << "NO" << endl;
        return 0;
      }
    }
  }
  for (int k = 0; k < y; k++) {
    if (m[x - 1][k] != m[x - 1][0]) {
      cout << "NO" << endl;
      return 0;
    }
  }
  cout << "YES" << endl;
  return 0;
}
