#include <bits/stdc++.h>
using namespace std;
signed main(int argc, char* argv[]) {
  ios::sync_with_stdio(0);
  cin.tie(0);
  int h, w;
  cin >> h >> w;
  string s[105];
  for (int i = 0; i < h; i++) cin >> s[i];
  if ((h % 3) && (w % 3)) {
    cout << "NO\n";
    return 0;
  }
  bool out = true;
  if (!(h % 3)) {
    if (s[h / 3][0] == s[0][0] || s[h / 3][0] == s[2 * h / 3][0] ||
        s[0][0] == s[2 * h / 3][0]) {
      out = false;
    }
    for (int k = 0; k < 3; k++) {
      for (int i = 0; i < h / 3; i++) {
        for (int j = 0; j < w; j++) {
          if (s[i + (k * (h / 3))][j] != s[k * (h / 3)][0]) {
            out = false;
          }
        }
      }
    }
    if (out) {
      cout << "YES\n";
      return 0;
    }
  }
  if (!(w % 3)) {
    out = true;
    if (s[0][w / 3] == s[0][0] || s[0][w / 3] == s[0][2 * w / 3] ||
        s[0][0] == s[0][2 * w / 3]) {
      out = false;
    }
    for (int i = 0; i < h; i++) {
      for (int k = 0; k < 3; k++) {
        for (int j = 0; j < w / 3; j++) {
          if (s[i][j + (k * (w / 3))] != s[0][k * (w / 3)]) {
            out = false;
          }
        }
      }
    }
  }
  if (out)
    cout << "YES\n";
  else
    cout << "NO\n";
  return 0;
}
