#include <bits/stdc++.h>
using namespace std;
#pragma GCC target("avx2")
#pragma GCC optimization("unroll-loops")
#pragma GCC optimize("O2")
int main() {
  long long n, m;
  cin >> n >> m;
  vector<vector<char> > v(n, vector<char>(m));
  map<char, long long> m1;
  for (long long i = 0; i < n; i++) {
    for (long long j = 0; j < m; j++) {
      cin >> v[i][j];
      m1[v[i][j]]++;
    }
  }
  map<long long, long long> m2;
  for (auto it : m1) {
    m2[it.second]++;
  }
  if (m2.size() != 1 || m2.begin()->second != 3) {
    cout << "NO";
    return 0;
  }
  if (n % 3 == 0) {
    set<char> s;
    for (long long i = 0; i < n / 3; i++) {
      for (long long j = 0; j < m; j++) {
        s.insert(v[i][j]);
      }
    }
    set<char> s2;
    for (long long i = n / 3; i < 2 * (n / 3); i++) {
      for (long long j = 0; j < m; j++) {
        s2.insert(v[i][j]);
      }
    }
    set<char> s3;
    for (long long i = 2 * (n / 3); i < n; i++) {
      for (long long j = 0; j < m; j++) {
        s3.insert(v[i][j]);
      }
    }
    if (s.size() == 1 && s2.size() == 1 && s3.size() == 1) {
      cout << "YES";
      return 0;
    }
  }
  if (m % 3 == 0) {
    set<char> s;
    for (long long i = 0; i < m / 3; i++) {
      for (long long j = 0; j < n; j++) {
        s.insert(v[j][i]);
      }
    }
    set<char> s2;
    for (long long i = m / 3; i < 2 * (m / 3); i++) {
      for (long long j = 0; j < n; j++) {
        s2.insert(v[j][i]);
      }
    }
    set<char> s3;
    for (long long i = 2 * (m / 3); i < m; i++) {
      for (long long j = 0; j < n; j++) {
        s3.insert(v[j][i]);
      }
    }
    if (s.size() == 1 && s2.size() == 1 && s3.size() == 1) {
      cout << "YES";
      return 0;
    }
  }
  cout << "NO";
  return 0;
}
