#include <bits/stdc++.h>
using namespace std;
char a[105][105];
int main() {
  int n, m;
  scanf("%d%d", &n, &m);
  for (int i = 0; i < n; i++) scanf("%s", a[i]);
  int flag = 1;
  if (n % 3 == 0) {
    int nn = n / 3;
    for (int i = 0; i < n; i++)
      for (int j = 0; j < m; j++)
        if (a[i][j] != a[i / nn * nn][0]) flag = 0;
    if (a[0][0] == a[nn][0] || a[0][0] == a[2 * nn][0] ||
        a[2 * nn][0] == a[nn][0])
      flag = 0;
  } else
    flag = 0;
  if (flag == 0 && m % 3 == 0) {
    flag = 1;
    int mm = m / 3;
    for (int j = 0; j < m; j++)
      for (int i = 0; i < n; i++)
        if (a[i][j] != a[0][j / mm * mm]) flag = 0;
    if (a[0][0] == a[0][mm] || a[0][0] == a[0][2 * mm] ||
        a[0][2 * mm] == a[0][mm])
      flag = 0;
  }
  if (!flag)
    printf("NO\n");
  else
    printf("YES\n");
}
