#include <bits/stdc++.h>
using namespace std;
char a[110][110];
int main() {
  int n, m, i, j, flag;
  char ch1, ch2, ch3;
  cin >> n >> m;
  for (i = 0; i < n; i++) scanf("%s", a[i]);
  if (n % 3 == 0) {
    ch1 = a[0][0];
    flag = 1;
    for (i = 0; i < n / 3; i++)
      for (j = 0; j < m; j++)
        if (a[i][j] != ch1) flag = 0;
    ch2 = a[n / 3][0];
    for (i = n / 3; i < 2 * n / 3; i++)
      for (j = 0; j < m; j++)
        if (a[i][j] != ch2) flag = 0;
    ch3 = a[2 * n / 3][0];
    for (i = 2 * n / 3; i < n; i++)
      for (j = 0; j < m; j++)
        if (a[i][j] != ch3) flag = 0;
    if (flag && ch1 != ch2 && ch1 != ch3 && ch2 != ch3) {
      cout << "YES" << endl;
      return 0;
    }
  }
  if (m % 3 == 0) {
    ch1 = a[0][0];
    flag = 1;
    for (i = 0; i < n; i++)
      for (j = 0; j < m / 3; j++)
        if (a[i][j] != ch1) flag = 0;
    ch2 = a[0][m / 3];
    for (i = 0; i < n; i++)
      for (j = m / 3; j < 2 * m / 3; j++)
        if (a[i][j] != ch2) flag = 0;
    ch3 = a[0][2 * m / 3];
    for (i = 0; i < n; i++)
      for (j = 2 * m / 3; j < m; j++)
        if (a[i][j] != ch3) flag = 0;
    if (flag && ch1 != ch2 && ch1 != ch3 && ch2 != ch3) {
      cout << "YES" << endl;
      return 0;
    }
  }
  cout << "NO" << endl;
  ;
  return 0;
}
