#include <bits/stdc++.h>
using namespace std;
bool yes(char a[], int len) {
  for (int i = 1; i <= len; i++)
    if (a[i] == -1) return false;
  if (len % 3) return false;
  int x = len / 3;
  for (int i = 1; i <= x; i++)
    if (a[i] != a[1]) return false;
  for (int i = x + 1; i <= x + x; i++)
    if (a[i] != a[x + 1]) return false;
  for (int i = x + x + 1; i <= x + x + x; i++)
    if (a[i] != a[x + x + 1]) return false;
  if (a[1] == a[x + 1] or a[1] == a[x + x + 1] or a[x + 1] == a[x + x + 1])
    return false;
  return true;
}
char a[110][110];
char wow[110], wol[110];
int n, m;
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cin >> n >> m;
  for (int i = 1; i <= n; i++) cin >> 1 + a[i];
  memset(wow, -1, sizeof wow);
  memset(wol, -1, sizeof wol);
  for (int i = 1; i <= n; i++) {
    bool is = 1;
    for (int j = 1; j <= m and is; j++)
      if (a[i][j] != a[i][1]) is = 0;
    if (is) wow[i] = a[i][1];
  }
  for (int j = 1; j <= m; j++) {
    bool is = 1;
    for (int i = 1; i <= n and is; i++)
      if (a[i][j] != a[1][j]) is = 0;
    if (is) wol[j] = a[1][j];
  }
  cout << ((yes(wow, n) or yes(wol, m)) ? "YES" : "NO") << '\n';
  return 0;
}
