#include <bits/stdc++.h>
using namespace std;
class flag {
 public:
  string* str;
  int indi = 0;
  int indj = 0;
  int d;
  int sh;
  flag() {
    str = NULL;
    d = 0;
    sh = 0;
  }
  flag(const int& s, const int& dl) {
    d = dl;
    sh = s;
    str = new string[sh];
  }
  ~flag() { delete[] str; }
  friend istream& operator>>(istream& is, flag& f) {
    for (int i(0); i < f.sh; i++) {
      is.get();
      is >> f.str[i];
    }
    return is;
  }
  bool check() {
    if (indj == 0 && indi == 0)
      return true;
    else
      return false;
  }
};
class stroka : public flag {
  char c;

 public:
  stroka() : flag::flag() { c = '0'; }
  void stroka1(char ch, flag& f) {
    c = ch;
    lookaround(f);
  }
  bool checkcollor(flag& f) {
    for (int j(indj); j < f.indj; j++)
      for (int i(indi); i < f.indi; i++)
        if (f.str[j][i] != c) return false;
    return true;
  }
  void lookaround(flag& f) {
    int i = f.indi;
    int j = f.indj;
    indi = f.indi;
    indj = f.indj;
    while (i != f.d && f.str[j][i] == c) i++;
    d = i - f.indi;
    if (i < f.d)
      swap(f.indi, i);
    else {
      f.indi = i;
      i--;
    }
    while (j != f.sh && f.str[j][i] == c) j++;
    sh = j - f.indj;
    if (j < f.sh && f.indi == f.d)
      swap(f.indj, j);
    else if (j < f.sh && f.indi < f.d) {
      f.indj = j - 1;
      j = 0;
    } else {
      f.indj = j;
      j = 0;
    }
    if (!checkcollor(f)) {
      d = -1;
      sh = -1;
    }
    if (f.indj == f.sh) f.indj = 0;
    if (f.indi == f.d) f.indi = 0;
  }
  bool compare(stroka& st) {
    if (st.sh == sh && st.d == d) return true;
    return false;
  }
};
int main() {
  int d, sh;
  cin >> sh >> d;
  flag f(sh, d);
  cin >> f;
  stroka r;
  stroka g;
  stroka b;
  short s = 0;
  char c = f.str[0][0];
  while (s != 3) switch (c) {
      case 'R':
        r.stroka1('R', f);
        c = f.str[f.indj][f.indi];
        s++;
        break;
      case 'G':
        g.stroka1('G', f);
        c = f.str[f.indj][f.indi];
        s++;
        break;
      case 'B':
        b.stroka1('B', f);
        c = f.str[f.indj][f.indi];
        s++;
        break;
    }
  (r.compare(g) && g.compare(b) && f.check()) ? cout << "YES" : cout << "NO";
  return 0;
}
