#include <bits/stdc++.h>
using namespace std;
int main() {
  int h, w, JC, FC = 0, C;
  string s;
  cin >> h >> w;
  for (int i = 1; i <= h; i++) {
    cin >> s;
    JC = 0;
    for (int j = 1; j <= w; j++) {
      if (s[j - 1] != s[j]) {
        JC += 1;
      }
      if (JC == w - 1) {
        FC += 1;
      }
      if (C >= 1 && C != FC) {
        cout << "No" << endl;
        exit(0);
      }
      C = FC;
    }
  }
  if (FC == h) {
    cout << "No" << endl;
  } else {
    cout << "Yes" << endl;
  }
  return 0;
}
