#include <bits/stdc++.h>
using namespace std;
bool debug = 0;
int n, m, k;
int dx[4] = {0, 1, 0, -1}, dy[4] = {1, 0, -1, 0};
string direc = "RDLU";
long long ln, lk, lm;
void etp(bool f = 0) {
  puts(f ? "YES" : "NO");
  exit(0);
}
void addmod(int &x, int y, int mod = 1000000007) {
  assert(y >= 0);
  x += y;
  if (x >= mod) x -= mod;
  assert(x >= 0 && x < mod);
}
void et() {
  puts("-1");
  exit(0);
}
char s[125][125];
set<char> ss;
bool ck(int l, int r, int u, int d, char x) {
  for (int j = u; j <= d; j++)
    for (int i = l; i <= r; i++)
      if (s[j][i] != x) return 0;
  return 1;
}
void fmain(int tid) {
  scanf("%d%d", &n, &m);
  for (int(i) = 1; (i) <= (int)(n); (i)++) scanf("%s", s[i] + 1);
  bool ok = ck(1, m, 1, 1, s[1][1]);
  if (ok) {
    int j = 1, pre = 1;
    while (j <= n && s[j][1] == s[pre][1]) j++;
    if (!ck(1, m, pre, j - 1, s[pre][1])) etp();
    ss.insert(s[pre][1]);
    int dis = j - pre;
    pre = j;
    while (j <= n && s[j][1] == s[pre][1]) j++;
    if (j == n + 1) etp();
    if (!ck(1, m, pre, j - 1, s[pre][1])) etp();
    ss.insert(s[pre][1]);
    if (dis != j - pre) etp();
    pre = j;
    while (j <= n && s[j][1] == s[pre][1]) j++;
    if (j != n + 1) etp();
    if (!ck(1, m, pre, j - 1, s[pre][1])) etp();
    ss.insert(s[pre][1]);
    if (dis != j - pre) etp();
    if (ss.size() != 3) etp();
  } else {
    int j = 1, pre = 1;
    while (j <= m && s[1][j] == s[1][pre]) j++;
    if (!ck(pre, j - 1, 1, n, s[1][pre])) etp();
    ss.insert(s[1][pre]);
    int dis = j - pre;
    pre = j;
    while (j <= m && s[1][j] == s[1][pre]) j++;
    if (j == m + 1) etp();
    if (!ck(pre, j - 1, 1, n, s[1][pre])) etp();
    ss.insert(s[1][pre]);
    if (dis != j - pre) etp();
    pre = j;
    while (j <= m && s[1][j] == s[1][pre]) j++;
    if (j != m + 1) etp();
    if (!ck(pre, j - 1, 1, n, s[1][pre])) etp();
    ss.insert(s[1][pre]);
    if (dis != j - pre) etp();
    if (ss.size() != 3) etp();
  }
  etp(1);
}
int main() {
  int t = 1;
  for (int(i) = 1; (i) <= (int)(t); (i)++) {
    fmain(i);
  }
  return 0;
}
