#include <bits/stdc++.h>
using namespace std;
int n, m;
char s[110][110];
void work1() {
  if (n % 3) {
    puts("NO");
    return;
  }
  int k = n / 3;
  if (s[0][0] == s[k][0] || s[0][0] == s[k * 2][0] || s[k][0] == s[k * 2][0]) {
    puts("NO");
    return;
  }
  for (int h = 0; h < 3; h++) {
    for (int i = 0; i < k; i++) {
      for (int j = 0; j < m; j++) {
        if (s[h * k][0] != s[h * k + i][j]) {
          puts("NO");
          return;
        }
      }
    }
  }
  puts("YES");
}
void work2() {
  if (m % 3) {
    puts("NO");
    return;
  }
  int k = m / 3;
  if (s[0][0] == s[0][k] || s[0][0] == s[0][k * 2] || s[0][k] == s[0][k * 2]) {
    puts("NO");
    return;
  }
  for (int h = 0; h < 3; h++) {
    for (int i = 0; i < k; i++) {
      for (int j = 0; j < n; j++) {
        if (s[0][h * k] != s[j][h * k + i]) {
          puts("NO");
          return;
        }
      }
    }
  }
  puts("YES");
}
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 0; i < n; i++) {
    scanf("%s", s[i]);
  }
  bool f = true;
  for (int i = 1; i < m; i++) {
    if (s[0][i] != s[0][i - 1]) {
      f = false;
      break;
    }
  }
  if (f) {
    work1();
  } else {
    work2();
  }
  return 0;
}
