#include <bits/stdc++.h>
using namespace std;
int main() {
  int i, j;
  int dif;
  int n, m;
  bool ans = true;
  char flag[100][101];
  cin >> n >> m;
  for (i = 0; i < n; i++) cin >> flag[i];
  for (i = 0; i < n; i++) {
    dif = flag[i][0];
    for (j = 1; j < m; j++)
      if (flag[i][j] != dif) ans = false;
  }
  for (i = 1; i < n - 1; i++)
    for (j = 0; j < m; j++)
      if (flag[i][j] == flag[i - 1][j] || flag[i][j] == flag[i + 1][j]) {
        ans = false;
        break;
      }
  if (ans)
    cout << "YES" << endl;
  else
    cout << "NO" << endl;
  return 0;
}
