#include <bits/stdc++.h>
using namespace std;
const int N = 1010;
char flag[N][N];
int main(void) {
  int n, m;
  scanf("%d %d", &n, &m);
  for (int i = 0; i < n; i++) {
    scanf(" %s", flag[i]);
  }
  if (m % 3 == 0) {
    set<int> s;
    bool flag = true;
    for (int k = 0; k < 3 and flag; k++) {
      int at = ::flag[0][k * m / 3];
      for (int j = k * m / 3; j < k * m / 3 + m / 3; j++) {
        for (int i = 0; i < n; i++) {
          if (s.count(::flag[i][j]) or ::flag[i][j] != at) flag = false;
        }
      }
      s.insert(at);
    }
    if (flag) {
      printf("YES\n");
      return 0;
    }
  }
  if (n % 3 == 0) {
    set<int> s;
    bool flag = true;
    for (int k = 0; k < 3 and flag; k++) {
      int at = ::flag[k * n / 3][0];
      for (int i = k * n / 3; i < k * n / 3 + n / 3; i++) {
        for (int j = 0; j < m; j++) {
          if (s.count(::flag[i][j]) or ::flag[i][j] != at) flag = false;
        }
      }
      s.insert(at);
    }
    if (flag) {
      printf("YES\n");
      return 0;
    }
  }
  printf("NO\n");
  return 0;
}
