#include <bits/stdc++.h>
int main() {
  int n, m;
  scanf("%d%d", &n, &m);
  getchar();
  char a[101][101];
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      scanf("%c", &a[i][j]);
    }
    getchar();
  }
  int f1 = 2, f2 = 2;
  if (n % 3 == 0) {
    if (a[0][0] != a[n / 3][0] && a[0][0] != a[n / 3 * 2][0] &&
        a[n / 3][0] != a[n / 3 * 2][0]) {
      f1 = 0;
      for (int i = 0; i < 3; i++) {
        for (int j = 0; j < n / 3; j++) {
          for (int t = 0; t < m; t++) {
            if (a[j + i * n / 3][t] != a[i * n / 3][0]) f1 = 1;
          }
        }
      }
    }
  }
  if (m % 3 == 0) {
    if (a[0][0] != a[0][m / 3] && a[0][0] != a[0][m / 3 * 2] &&
        a[0][m / 3] != a[0][m / 3 * 2]) {
      f2 = 0;
      for (int i = 0; i < 3; i++) {
        for (int j = 0; j < m / 3; j++) {
          for (int t = 0; t < n; t++) {
            if (a[t][j + i * m / 3] != a[0][i * m / 3]) f2 = 1;
          }
        }
      }
    }
  }
  if (f1 == 0 || f2 == 0)
    printf("YES\n");
  else
    printf("NO\n");
  return 0;
}
