#include <bits/stdc++.h>
using namespace std;
const long long int inf = 1e18 + 5;
const long long MOD = 1e9 + 7;
const int MAX = 1e9 + 10;
const long long int N = 1e6;
using namespace std;
vector<string> seq = {"RGB", "RBG", "BGR", "BRG", "GBR", "GRB"};
bool check(vector<string> matrix, int n, int m) {
  int h = n / 3;
  for (int i = 0; i < seq.size(); ++i) {
    bool isOk = true;
    string temp1(m, seq[i][0]), temp2(m, seq[i][1]), temp3(m, seq[i][2]);
    for (int j = 0; j < n; ++j) {
      if (j < h) {
        if (matrix[j] != temp1) {
          isOk = false;
          break;
        }
      } else if (j < 2 * h) {
        if (matrix[j] != temp2) {
          isOk = false;
          break;
        }
      } else {
        if (matrix[j] != temp3) {
          isOk = false;
          break;
        }
      }
    }
    if (isOk) return true;
  }
  return false;
}
void solve() {
  int n, m;
  cin >> n >> m;
  vector<string> matrix(n);
  for (int i = 0; i < n; ++i) {
    cin >> matrix[i];
  }
  if (n % 3 == 0 and check(matrix, n, m)) {
    cout << "YES" << endl;
    return;
  }
  vector<string> copy(m);
  for (int i = 0; i < m; ++i) {
    for (int j = 0; j < n; ++j) {
      copy[i] += matrix[j][i];
    }
  }
  if (m % 3 == 0 and check(copy, m, n)) {
    cout << "YES" << endl;
    return;
  }
  cout << "NO" << endl;
}
int main() {
  solve();
  return 0;
}
