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