#include <bits/stdc++.h>
using namespace std;
int main() {
  char *a, *b;
  int n, m, c = 1;
  cin >> n >> m;
  a = (char *)malloc(sizeof(char) * (m + 1));
  b = (char *)malloc(sizeof(char) * (m + 1));
  cin >> a;
  for (int i = 0; i < m - 1; i++) {
    if (a[i] != a[i + 1]) {
      c = 0;
      break;
    }
  }
  if (c == 1) {
    for (int i = 0; i < n - 1; i++) {
      cin >> b;
      for (int j = 0; j < m - 1; j++) {
        if (b[j] != b[j + 1]) {
          c = 0;
          break;
        }
      }
      if (c == 0) {
        cout << "NO";
        break;
      }
      if (strcmp(a, b) == 0) {
        c = 0;
        cout << "NO";
        break;
      }
      strcpy(a, b);
    }
    if (c == 1) {
      cout << "YES";
    }
  } else {
    cout << "NO";
  }
}
