#include <bits/stdc++.h>
char s[110][110];
int work(int init, int wid, int m) {
  int i, j, temp = 0;
  for (i = 0; i < wid; i++) {
    for (j = 0; j < m; j++)
      if (s[init][0] != s[i + init][j]) {
        temp = 1;
        break;
      }
    if (temp == 1) break;
  }
  if (temp == 0) return 1;
  return 0;
}
int work2(int init, int len, int n) {
  int i, j, temp = 0;
  for (i = 0; i < len; i++) {
    for (j = 0; j < n; j++)
      if (s[0][init] != s[j][i + init]) {
        temp = 1;
        break;
      }
    if (temp == 1) break;
  }
  if (temp == 0) return 1;
  return 0;
}
int main() {
  int n, m, i, j, flag = 0, temp;
  scanf("%d%d", &n, &m);
  for (i = 0; i < n; i++) scanf("%s", s[i]);
  if (n % 3 == 0) {
    if (s[0][0] != s[n / 3][0] && s[0][0] != s[n / 3 * 2][0] &&
        s[n / 3][0] != s[n / 3 * 2][0])
      temp = 1;
    else
      temp = 0;
    if (temp == 1) {
      if (work(0, n / 3, m) == 0) temp = 0;
      if (work(n / 3, n / 3, m) == 0) temp = 0;
      if (work(n / 3 * 2, n / 3, m) == 0) temp = 0;
    }
    if (temp == 1) flag = 1;
  }
  if (m % 3 == 0) {
    if (s[0][0] != s[0][m / 3] && s[0][0] != s[0][m / 3 * 2] &&
        s[0][m / 3] != s[0][m / 3 * 2])
      temp = 1;
    else
      temp = 0;
    if (temp == 1) {
      if (work2(0, m / 3, n) == 0) temp = 0;
      if (work2(m / 3, m / 3, n) == 0) temp = 0;
      if (work2(m / 3 * 2, m / 3, n) == 0) temp = 0;
    }
    if (temp == 1) flag = 1;
  }
  if (flag == 1)
    printf("YES\n");
  else
    printf("NO\n");
  return 0;
}
