// Try Codeforces
// author: Leonardone @ NEETSDKASU
import std.stdio, std.string, std.array, std.algorithm, std.conv;

void main() {
    auto nm = to!(int[])(split(chomp(readln())));
    int n = nm[0], m = nm[1];
    auto xss = appender!(string[])();
    for (int i = 0; i < n; i++) {
        xss.put(chomp(readln()));
        if (!xss.data[i].count!( (a) => a == 'R' || a == 'G' || a == 'B' )) {
            writeln("NO");
            return;
        }
    }
    auto ans = false;
    if (n % 3 == 0) {
        int u = n / 3;
        bool flag = true;
        for (int x = 0; x < m; x++) {
            for (int y = 0; y < n; y++) {
                auto p = xss.data[y][x];
                auto a = xss.data[y/u*u][x];
                auto b = xss.data[(y/u+1)%3*u][x];
                auto c = xss.data[(y/u+2)%3*u][x];
                flag = flag && (p == a && p != b && p != c) && (x == 0 || p == xss.data[y][x-1]);
            }
        }
        ans = ans || flag;
    }
    if (m % 3 == 0) {
        int u = m / 3;
        bool flag = true;
        for (int y = 0; y < n; y++) {
            for (int x = 0; x < m; x++) {
                auto p = xss.data[y][x];
                auto a = xss.data[y][x/u*u];
                auto b = xss.data[y][(x/u+1)%3*u];
                auto c = xss.data[y][(x/u+2)%3*u];
                flag = flag && (p == a && p != b && p != c) && (y == 0 || p == xss.data[y-1][x]);
            }
        }
        ans = ans || flag;
    }
    writeln(ans ? "YES" : "NO");
}