#include <bits/stdc++.h>
using namespace std;
bool solution(vector<vector<int>> flag, int n, int m) {
  int prevLine = -1;
  for (int i = 0; i < n; i++) {
    int curLine = flag[i][0];
    if (prevLine == curLine) {
      return false;
    } else {
      prevLine = curLine;
      for (int j = 0; j < m - 1; j++) {
        if (flag[i][j] != flag[i][j + 1]) {
          return false;
        }
      }
    }
  }
  return true;
}
int main(int argc, const char* argv[]) {
  vector<vector<int>> flag;
  int n, m;
  cin >> n;
  cin >> m;
  for (int i = 0; i < n; i++) {
    vector<int> row;
    for (int j = 0; j < m; j++) {
      char number;
      cin >> number;
      row.push_back(number - 48);
    }
    flag.push_back(row);
  }
  bool correct = solution(flag, n, m);
  cout << (correct ? "YES" : "NO") << endl;
  return 0;
}
