#include <bits/stdc++.h>
using namespace std;
const int maxn = 105;
int n, m;
char g[maxn][maxn];
int vis[3];
map<char, int> mp;
int main() {
  mp['R'] = 0;
  mp['G'] = 1;
  mp['B'] = 2;
  scanf("%d%d", &n, &m);
  for (int i = 0; i < n; i++) scanf("%s", g[i]);
  bool ok = true;
  if (g[0][0] == g[0][m - 1] && n % 3 == 0) {
    int w = n / 3;
    for (int i = 0; i < n && ok; i++) {
      char x = g[i][0];
      int but = i + w;
      for (; i < but; i++)
        for (int j = 0; j < m; j++)
          if (g[i][j] != x) ok = false;
      int id = mp[x];
      if (vis[id]) {
        ok = false;
        break;
      }
      vis[id] = 1;
      i--;
    }
  } else if (g[0][0] == g[n - 1][0] && m % 3 == 0) {
    int w = m / 3;
    for (int j = 0; j < m && ok; j++) {
      char x = g[0][j];
      int r = j + w;
      for (; j < r; j++)
        for (int i = 0; i < n; i++)
          if (g[i][j] != x) ok = false;
      int id = mp[x];
      if (vis[id]) {
        ok = false;
        break;
      }
      vis[id] = 1;
      j--;
    }
  } else
    ok = false;
  puts(ok ? "YES" : "NO");
  return 0;
}
