#include <bits/stdc++.h>
using namespace std;
inline void splay(int &v) {
  v = 0;
  char c = 0;
  int p = 1;
  while (c < '0' || c > '9') {
    if (c == '-') p = -1;
    c = getchar();
  }
  while (c >= '0' && c <= '9') {
    v = (v << 3) + (v << 1) + c - '0';
    c = getchar();
  }
  v *= p;
}
char s[505][505], t[505][505];
void calc(char s[][505], int n, int m) {
  bool f = 1;
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++) {
      if (i != 1 && i != n / 3 + 1 && i != n / 3 * 2 + 1 &&
          s[i][j] != s[i - 1][j])
        f = 0;
      if (j != 1 && s[i][j] != s[i][j - 1]) f = 0;
    }
  }
  if (s[1][1] == s[n / 3 + 1][1] || s[n / 3 * 2 + 1][1] == s[n / 3 + 1][1] ||
      s[1][1] == s[n / 3 * 2 + 1][1])
    f = 0;
  if (f) puts("YES"), exit(0);
}
int main() {
  int n, m;
  splay(n), splay(m);
  for (int i = 1; i <= n; i++) {
    scanf("%s", s[i] + 1);
  }
  if (n % 3 == 0) {
    calc(s, n, m);
  }
  if (m % 3 == 0) {
    for (int i = 1; i <= n; i++) {
      for (int j = 1; j <= m; j++) {
        t[j][i] = s[i][j];
      }
    }
    calc(t, m, n);
  }
  puts("NO");
}
