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