#include <bits/stdc++.h>
using namespace std;
const int N = 105;
int n, m;
int k = 1;
char s[N][N];
int a[N][N];
set<int> st;
map<int, int> mp;
int main() {
  cin >> n >> m;
  memset(a, -1, sizeof(a));
  for (int i = 1; i <= n; ++i) {
    scanf("%s", s[i] + 1);
  }
  for (int i = 1; i <= n; ++i) {
    for (int j = 1; j <= m; ++j) {
      a[i][j] = s[i][j] - '0';
    }
  }
  for (int i = 1; i <= n; ++i) {
    st.clear();
    for (int j = 1; j <= m; ++j) {
      st.insert(a[i][j]);
    }
    if (st.size() != 1) {
      k = 0;
      break;
    }
    mp[i] = *st.begin();
  }
  if (k == 0) {
    puts("NO");
    return 0;
  }
  for (int i = 1; i <= n; ++i) {
    if (i == 1) {
      if (mp[1] == mp[2]) {
        k = 0;
        break;
      }
      continue;
    }
    if (i == n) {
      if (mp[n] == mp[n - 1]) {
        k = 0;
        break;
      }
      continue;
    }
    if (mp[i] == mp[i - 1]) {
      k = 0;
      break;
    }
  }
  if (k == 1) {
    puts("YES");
  } else {
    puts("NO");
  }
  return 0;
}
