#include <bits/stdc++.h>
using namespace std;
const int INF = 0x3f3f3f3f;
const double PI = acos(-1.0);
const int T = 110;
int linR, linB, linG;
vector<pair<int, int> > tR, tB, tG;
char g[T][T];
bool vis[T][T];
int iniR[T];
int iniG[T];
int iniB[T];
int n, m;
int dfs(int i, int j) {
  vis[i][j] = 1;
  int ans = 1;
  if (j + 1 < m and !vis[i][j + 1] and g[i][j] == g[i][j + 1])
    ans += dfs(i, j + 1);
  return ans;
}
bool check() {
  for (int i = 0; i < n; i++)
    for (int j = 0; j < m; j++)
      if (g[i][j] != 'R' and g[i][j] != 'B' and g[i][j] != 'G') return 0;
  return 1;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin >> n >> m;
  for (int i = 0; i < n; i++)
    for (int j = 0; j < m; j++) cin >> g[i][j];
  if (!check()) {
    cout << "NO" << '\n';
    return 0;
  }
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      if (g[i][j] == 'G' and !vis[i][j]) {
        tG.emplace_back(i, dfs(i, j));
        iniG[linG] = j;
        linG++;
      } else if (g[i][j] == 'R' and !vis[i][j]) {
        tR.emplace_back(i, dfs(i, j));
        iniR[linR] = j;
        linR++;
      } else if (g[i][j] == 'B' and !vis[i][j]) {
        tB.emplace_back(i, dfs(i, j));
        iniB[linB] = j;
        linB++;
      }
    }
  }
  bool ok = tG.size() and tB.size() and tR.size();
  if (!(linG == linR and linG == linB)) {
    cout << "NO" << '\n';
    return 0;
  }
  ok &= (tG[0].second == tB[0].second and tG[0].second == tR[0].second);
  for (int i = 1; i < tG.size(); i++) {
    ok &= (tR[i].first == (tR[i - 1].first + 1) and
           tR[i].second == tR[i - 1].second);
    ok &= (tB[i].first == (tB[i - 1].first + 1) and
           tB[i].second == tB[i - 1].second);
    ok &= (tG[i].first == (tG[i - 1].first + 1) and
           tG[i].second == tG[i - 1].second);
    ok &= (iniG[i] == iniG[i - 1]);
    ok &= (iniB[i] == iniB[i - 1]);
    ok &= (iniR[i] == iniR[i - 1]);
    ok &= (tG[i].second == tB[i].second and tG[i].second == tR[i].second);
  }
  if (ok)
    cout << "YES" << '\n';
  else
    cout << "NO" << '\n';
  return 0;
}
