// tested by Hightail - https://github.com/dj3500/hightail
import std.stdio, std.string, std.conv, std.algorithm;
import std.range, std.array, std.math, std.typecons, std.container, core.bitop;
import std.datetime, std.bigint;

int n, m;
char[][] flag;

void main() {
    scan(n, m);

    if (n % 3 && m % 3) {
        writeln("NO");
        return;
    }

    flag = new char[][](n, m);
    iota(n).each!(i => flag[i][] = readln.chomp);

    debug {
        writefln("%(%(%s %)\n%)", flag);
    }

    int r, c;

    if (n % 3 == 0) {
        r = n / 3;

        auto rgb = new int[](3);

        bool ok = true;

        foreach (k ; 0 .. 3) {
            char ch = flag[k * r][0];

            if (ch == 'R') rgb[0]++;
            else if (ch == 'G') rgb[1]++;
            else rgb[2]++;

            foreach (i ; k * r .. k * r + r) {
                foreach (j ; 0 .. m) {
                    if (flag[i][j] != ch) ok = false;
                }
            }
        }

        if (rgb == [1, 1, 1] && ok) {
            writeln("YES");
            return;
        }
    }

    if (m % 3 == 0) {
        c = m / 3;

        auto rgb = new int[](3);

        bool ok = true;

        foreach (k ; 0 .. 3) {
            char ch = flag[0][k * c];

            if (ch == 'R') rgb[0]++;
            else if (ch == 'G') rgb[1]++;
            else rgb[2]++;

            foreach (j ; k * c .. k * c + c) {
                foreach (i ; 0 .. n) {
                    if (flag[i][j] != ch) ok = false;
                }
            }

            if (rgb == [1, 1, 1] && ok) {
                writeln("YES");
                return;
            }
        }
    }

    writeln("NO");
}



void scan(T...)(ref T args) {
    string[] line = readln.split;
    foreach (ref arg; args) {
        arg = line.front.to!(typeof(arg));
        line.popFront();
    }
    assert(line.empty);
}


void fillAll(R, T)(ref R arr, T value) {
    static if (is(typeof(arr[] = value))) {
        arr[] = value;
    }
    else {
        foreach (ref e; arr) {
            fillAll(e, value);
        }
    }
}