#include <bits/stdc++.h>
using namespace std;
char s[110][110];
char ss[110][110];
int main() {
  int n, m;
  cin >> n >> m;
  for (int i = 1; i <= n; i++) {
    scanf("%s", s[i] + 1);
    for (int j = 1; j <= m; j++) ss[i][j] = s[i][j];
  }
  if (n % 3 == 0) {
    int flag = 0;
    for (int i = 1; i <= n; i++) {
      for (int j = 1; j <= m; j++) {
        for (int k = j + 1; k <= m; k++) {
          if (s[i][j] != s[i][k]) flag = 1;
        }
      }
    }
    if (!flag) {
      int N = n / 3;
      if (s[1][1] == s[N + 1][1] || s[N + 1][1] == s[2 * N + 1][1] ||
          s[1][1] == s[2 * N + 1][1]) {
        flag = 1;
      }
      if (!flag) {
        for (int i = 1; i <= n; i += N) {
          for (int j = i + 1; j < i + N; j++) {
            if (s[i][1] != s[j][1]) flag = 1;
          }
        }
      }
      if (!flag) {
        puts("YES");
        return 0;
      }
    }
  }
  swap(n, m);
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++) {
      s[i][j] = ss[j][i];
    }
  }
  if (n % 3 == 0) {
    int flag = 0;
    for (int i = 1; i <= n; i++) {
      for (int j = 1; j <= m; j++) {
        for (int k = j + 1; k <= m; k++) {
          if (s[i][j] != s[i][k]) flag = 1;
        }
      }
    }
    if (!flag) {
      int N = n / 3;
      if (s[1][1] == s[N + 1][1] || s[N + 1][1] == s[2 * N + 1][1] ||
          s[1][1] == s[2 * N + 1][1]) {
        flag = 1;
      }
      if (!flag) {
        for (int i = 1; i <= n; i += N) {
          for (int j = i + 1; j < i + N; j++) {
            if (s[i][1] != s[j][1]) flag = 1;
          }
        }
      }
      if (!flag) {
        puts("YES");
        return 0;
      }
    }
  }
  puts("NO");
}
