#include <bits/stdc++.h>
const long long oo = 2 * 1000 * 1000 * 1000;
const int _cnt = 1000 * 1000;
const int _p = 1000 * 1000 * 1000 + 7;
long long o(long long x) { return x % _p; }
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
int lcm(int a, int b) { return a * b / gcd(a, b); }
using namespace std;
void file_put() {
  freopen("filename.in", "r", stdin);
  freopen("filename.out", "w", stdout);
}
struct squaretype {
  int x, r;
};
string st;
int a[1000], n, m;
bool check(string st) {
  for (int i = 0; i < st.length(); i++)
    if (st[i] != st[0]) return false;
  return true;
}
int main() {
  scanf("%d%d", &n, &m);
  cin.ignore();
  for (int i = 1; i <= n; i++) {
    getline(cin, st);
    if (check(st)) {
      a[i] = st[0];
      continue;
    }
    printf("NO\n");
    return 0;
  }
  for (int i = 2; i <= n; i++)
    if (a[i] == a[i - 1]) {
      printf("NO\n");
      return 0;
    }
  printf("YES\n");
  return 0;
}
