#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  long long n, t, i, j, m;
  string s;
  cin >> n >> m;
  vector<vector<char>> vect(n, vector<char>(m));
  bool f;
  for (i = 0; i < n; i++) {
    for (j = 0; j < m; j++) {
      cin >> vect[i][j];
    }
  }
  if (n % 3 == 0) {
    f = true;
    set<char> ms, ms1, ms3, ms4;
    for (i = 0; f && i < n / 3; i++) {
      for (j = 0; j < m; j++) {
        ms.insert(vect[i][j]);
        ms1.insert(vect[i][j]);
      }
    }
    if (ms.size() != 1 || ms1.size() != 1) {
      f = false;
    }
    for (i = n / 3; f && i < (2 * (n / 3)); i++) {
      for (j = 0; j < m; j++) {
        ms.insert(vect[i][j]);
        ms3.insert(vect[i][j]);
      }
    }
    if (ms.size() != 2 || ms3.size() != 1) {
      f = false;
    }
    for (i = (2 * (n / 3)); f && i < n; i++) {
      for (j = 0; j < m; j++) {
        ms.insert(vect[i][j]);
        ms4.insert(vect[i][j]);
      }
    }
    if (ms.size() == 3 && f && ms4.size() == 1) {
      cout << "YES";
      return 0;
    }
  }
  if (m % 3 == 0) {
    f = true;
    set<char> ms2, ms5, ms6, ms7;
    for (i = 0; f && i < m / 3; i++) {
      for (j = 0; j < n; j++) {
        ms2.insert(vect[j][i]);
        ms5.insert(vect[j][i]);
      }
    }
    if (ms2.size() != 1 || ms5.size() != 1) {
      f = false;
    }
    for (i = m / 3; f && i < (2 * (m / 3)); i++) {
      for (j = 0; j < n; j++) {
        ms2.insert(vect[j][i]);
        ms6.insert(vect[j][i]);
      }
    }
    if (ms2.size() != 2 || ms6.size() != 1) {
      f = false;
    }
    for (i = (2 * (m / 3)); f && i < m; i++) {
      for (j = 0; j < n; j++) {
        ms2.insert(vect[j][i]);
        ms7.insert(vect[j][i]);
      }
    }
    if (ms2.size() == 3 && f && ms7.size() == 1) {
      cout << "YES";
      return 0;
    }
  }
  cout << "NO";
}
