#include <bits/stdc++.h>
using namespace std;
char flag[100][101];
size_t m, n;
bool same_color(char c, size_t s, size_t t, size_t u, size_t v) {
  for (size_t i = s; i < t; i++)
    for (size_t j = u; j < v; j++)
      if (flag[i][j] != c) return false;
  return true;
}
bool valid_horizontal_stripes() {
  if (n % 3 != 0) return false;
  size_t p = n / 3, q = p << 1;
  char c1 = flag[0][0], c2 = flag[p][0], c3 = flag[q][0];
  if (c1 == c2 || c2 == c3 || c3 == c1) return false;
  return same_color(c1, 0, p, 0, m) && same_color(c2, p, q, 0, m) &&
         same_color(c3, q, n, 0, m);
}
bool valid_vertical_stripes() {
  if (m % 3 != 0) return false;
  size_t p = m / 3, q = p << 1;
  char c1 = flag[0][0], c2 = flag[0][p], c3 = flag[0][q];
  if (c1 == c2 || c2 == c3 || c3 == c1) return false;
  return same_color(c1, 0, n, 0, p) && same_color(c2, 0, n, p, q) &&
         same_color(c3, 0, n, q, m);
}
int main() {
  scanf("%u %u", &n, &m);
  for (size_t i = 0; i < n; i++) scanf("%s", flag[i]);
  if (valid_horizontal_stripes() || valid_vertical_stripes()) {
    printf("YES");
    return 0;
  }
  printf("NO");
}
