#include <bits/stdc++.h>
using namespace std;
int n, m;
char mp[110][110];
bool CheckRC() {
  for (int i = 1; i < n; i++)
    if (mp[i][0] != mp[i - 1][0]) return 0;
  return 1;
}
bool Check(int ty) {
  if ((ty == 0 && n % 3 != 0) || (ty == 1 && m % 3 != 0)) return 0;
  if (ty == 0 && (mp[0][0] == mp[n / 3][0] || mp[0][0] == mp[n / 3 * 2][0] ||
                  mp[n / 3][0] == mp[n / 3 * 2][0]))
    return 0;
  if (ty == 1 && (mp[0][0] == mp[0][m / 3] || mp[0][0] == mp[0][m / 3 * 2] ||
                  mp[0][m / 3] == mp[0][m / 3 * 2]))
    return 0;
  int tot = (ty == 0 ? m : n), l, r;
  for (int t = 0; t < 3; t++) {
    l = (ty == 0 ? n : m) / 3 * t;
    r = (ty == 0 ? n : m) / 3 * (t + 1);
    for (int i = l; i < r; i++)
      for (int j = 0; j < tot; j++)
        if ((ty == 0 && mp[i][j] != mp[l][0]) ||
            (ty == 1 && mp[j][i] != mp[0][l]))
          return 0;
  }
  return 1;
}
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 0; i < n; i++) scanf("%s", mp[i]);
  if (Check(CheckRC()))
    printf("YES\n");
  else
    printf("NO\n");
  return 0;
}
