#include <bits/stdc++.h>
using namespace std;
const long long int N = 1e9 + 100;
const int mod = 1e9 + 7, M = 1e6 + 100, se = 85 + 85;
int ans, a, b, c, d, n, m;
string s;
int main() {
  ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL);
  cin >> n >> m;
  char jad[n][m];
  for (int i = 0; i < n; i++)
    for (int j = 0; j < m; j++) cin >> jad[i][j];
  for (int i = 0; i < n; i++)
    for (int j = 1; j < m; j++)
      if (jad[i][j] != jad[i][j - 1]) return cout << "NO", 0;
  for (int i = 1; i < n; i++)
    for (int j = 0; j < m; j++)
      if (jad[i - 1][j] == jad[i][j]) return cout << "NO", 0;
  cout << "YES";
}
