#include <bits/stdc++.h>
using namespace std;
int n, m;
char t[101][101];
int main() {
  ios_base::sync_with_stdio(false);
  cin >> n >> m;
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++) {
      cin >> t[j][i];
    }
  }
  if (n % 3 == 0) {
    bool jo = true;
    vector<char> lines[3];
    for (int i = 1; i <= n / 3; i++) {
      for (int j = 1; j <= m; j++) {
        lines[0].push_back(t[j][i]);
      }
    }
    for (int i = n / 3 + 1; i <= n / 3 + n / 3; i++) {
      for (int j = 1; j <= m; j++) {
        lines[1].push_back(t[j][i]);
      }
    }
    for (int i = n / 3 + n / 3 + 1; i <= n; i++) {
      for (int j = 1; j <= m; j++) {
        lines[2].push_back(t[j][i]);
      }
    }
    for (int i = 0; i < 3; i++) {
      if (lines[i].size() == 1) continue;
      for (int j = 0; j < lines[i].size() - 1; j++) {
        if (lines[i][j] != lines[i][j + 1]) jo = false;
      }
    }
    if (lines[0][0] == lines[1][0] || lines[1][0] == lines[2][0] ||
        lines[2][0] == lines[0][0])
      jo = false;
    if (jo) {
      cout << "YES";
      return 0;
    }
  }
  if (m % 3 == 0) {
    bool jo = true;
    vector<char> lines[3];
    for (int i = 1; i <= m / 3; i++) {
      for (int j = 1; j <= n; j++) {
        lines[0].push_back(t[i][j]);
      }
    }
    for (int i = m / 3 + 1; i <= m / 3 + m / 3; i++) {
      for (int j = 1; j <= n; j++) {
        lines[1].push_back(t[i][j]);
      }
    }
    for (int i = m / 3 + m / 3 + 1; i <= m; i++) {
      for (int j = 1; j <= n; j++) {
        lines[2].push_back(t[i][j]);
      }
    }
    for (int i = 0; i < 3; i++) {
      if (lines[i].size() == 1) continue;
      for (int j = 0; j < lines[i].size() - 1; j++) {
        if (lines[i][j] != lines[i][j + 1]) jo = false;
      }
    }
    if (lines[0][0] == lines[1][0] || lines[1][0] == lines[2][0] ||
        lines[2][0] == lines[0][0])
      jo = false;
    if (jo) {
      cout << "YES";
      return 0;
    }
  }
  cout << "NO";
  return 0;
}
