#include <bits/stdc++.h>
using namespace std;
char arr[200][200];
int main() {
  int n, m, cnt = 0;
  scanf("%d %d", &n, &m);
  getchar();
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++) {
      scanf("%c", &arr[i][j]);
    }
    getchar();
  }
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j < m; j++) {
      if (arr[i][j] != arr[i][j + 1]) {
        cout << "NO";
        return 0;
      }
    }
  }
  for (int i = 1; i < n; i++) {
    if (arr[i][1] == arr[i + 1][1]) {
      cout << "NO";
      return 0;
    }
  }
  cout << "YES";
}
