#include <bits/stdc++.h>
using namespace std;
vector<string> transpose(const vector<string> &s) {
  int n = s.size(), m = s[0].size();
  vector<string> res(m);
  for (int i = 0; i < m; i++) {
    for (int j = 0; j < n; j++) {
      res[i] += s[j][i];
    }
  }
  return res;
}
char get_color(const string &s) {
  for (int i = 1; i < s.size(); i++) {
    if (s[i] != s[0]) {
      return 0;
    }
  }
  return s[0];
}
bool check(const vector<string> &s) {
  int n = s.size();
  if (n % 3) {
    return false;
  }
  set<char> colors;
  for (int k = 0; k < n; k += n / 3) {
    char c = get_color(s[k]);
    if (c == 0) {
      return false;
    }
    for (int i = k + 1; i < k + n / 3; i++) {
      char cc = get_color(s[i]);
      if (cc != c) {
        return false;
      }
    }
    colors.insert(c);
  }
  return colors.size() == 3;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  int n, m;
  cin >> n >> m;
  vector<string> s(n);
  for (int i = 0; i < n; i++) {
    cin >> s[i];
  }
  auto st = transpose(s);
  if (check(s) || check(st)) {
    cout << "YES\n";
  } else {
    cout << "NO\n";
  }
}
