#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  while (cin >> n >> m) {
    string s[101];
    int a = -1;
    for (int i = 0; i < n; ++i) cin >> s[i];
    int f = 0;
    for (int i = 0; i < n; ++i) {
      f = 0;
      for (int j = 1; j < m; ++j) {
        if (s[i][j] != s[i][0]) {
          f = 1;
          break;
        }
      }
      if (f == 1)
        break;
      else {
        if (s[i][0] - '0' != a)
          a = s[i][0] - '0';
        else {
          f = 1;
          break;
        }
      }
    }
    if (f == 1)
      cout << "NO" << endl;
    else
      cout << "YES" << endl;
  }
  return 0;
}
