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