#include <bits/stdc++.h>
using namespace std;
const int N = 1010;
int n, m;
char s[N][N], b[N][N];
bool rev() {
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      b[j][i] = s[i][j];
    }
  }
  swap(n, m);
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      s[i][j] = b[i][j];
    }
  }
  return true;
}
bool check(int x, int y) {
  vector<int> v;
  for (int i = 0; i < n; i += x) {
    for (int j = i; j <= i + x - 1; j++) {
      for (int k = 0; k < y; k++) {
        if (s[j][k] != s[i][0]) {
          return false;
        }
      }
    }
    v.push_back(s[i][0]);
  }
  sort(v.begin(), v.end());
  v.resize(unique(v.begin(), v.end()) - v.begin());
  return ((int)v.size()) == 3;
}
int main() {
  scanf("%d %d", &n, &m);
  for (int i = 0; i < n; i++) {
    scanf("%s", s[i]);
  }
  if (n % 3 == 0 && check(n / 3, m)) {
    puts("YES");
  } else if (m % 3 == 0 && rev() && check(n / 3, m)) {
    puts("YES");
  } else {
    puts("NO");
  }
  return 0;
}
