#include <bits/stdc++.h>
using namespace std;
long long n, m;
string s[105];
char a, b, c;
bool cek;
bool hori() {
  if (m % 3 != 0) {
    return false;
  }
  a = s[1][0];
  b = s[1][m / 3];
  c = s[1][2 * m / 3];
  if (a == b or a == c or b == c) return false;
  for (long long i = 1; i <= n; i++)
    for (long long j = 0; j <= m / 3 - 1; j++) {
      if (s[i][j] != a or s[i][j + m / 3] != b or s[i][j + 2 * m / 3] != c) {
        return false;
      }
    }
  return true;
}
bool verti() {
  if (n % 3 != 0) return false;
  a = s[1][0];
  b = s[1 + n / 3][0];
  c = s[1 + 2 * n / 3][0];
  if (a == b or b == c or a == c) {
    return false;
  }
  for (long long i = 1; i <= n / 3; i++)
    for (long long j = 0; j <= m - 1; j++) {
      if (s[i][j] != a or s[i + n / 3][j] != b or s[i + 2 * n / 3][j] != c) {
        return false;
      }
    }
  return true;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cin >> n >> m;
  for (long long i = 1; i <= n; i++) cin >> s[i];
  if (hori() or verti())
    cout << "YES";
  else
    cout << "NO";
}
