#include <bits/stdc++.h>
using namespace std;
int n, m, i, j;
string s[103];
bool ktra1() {
  if (n % 3 == 0) {
    static int chk[1000];
    fill_n(chk, 1000, 0);
    for (int i = 1; i <= n / 3; ++i) {
      for (int j = 1; j <= m; ++j) {
        chk[s[i][j]]++;
      }
    }
    if (chk[s[1][1]] != m * n / 3) return false;
    for (int i = n / 3 + 1; i <= 2 * n / 3; ++i) {
      for (int j = 1; j <= m; ++j) {
        chk[s[i][j]]++;
      }
    }
    if (chk[s[n / 3 + 1][1]] != m * n / 3) return false;
    for (int i = 2 * n / 3 + 1; i <= n; ++i) {
      for (int j = 1; j <= m; ++j) {
        chk[s[i][j]]++;
      }
    }
    if (chk[s[n][1]] != m * n / 3) return false;
  } else
    return false;
  return true;
}
bool ktra2() {
  if (m % 3 == 0) {
    static int chk[1000];
    fill_n(chk, 1000, 0);
    for (int j = 1; j <= m / 3; ++j) {
      for (int i = 1; i <= n; ++i) {
        chk[s[i][j]]++;
      }
    }
    if (chk[s[1][1]] != m * n / 3) return false;
    for (int j = m / 3 + 1; j <= 2 * m / 3; ++j) {
      for (int i = 1; i <= n; ++i) {
        chk[s[i][j]]++;
      }
    }
    if (chk[s[1][m / 3 + 1]] != m * n / 3) return false;
    for (int j = 2 * m / 3 + 1; j <= m; ++j) {
      for (int i = 1; i <= n; ++i) {
        chk[s[i][j]]++;
      }
    }
    if (chk[s[1][m]] != m * n / 3) return false;
  } else
    return false;
  return true;
}
int main() {
  cin >> n >> m;
  for (int i = 1; i <= n; ++i) cin >> s[i], s[i] = " " + s[i];
  if (ktra1() || ktra2())
    cout << "YES";
  else
    cout << "NO";
}
