#include <bits/stdc++.h>
using namespace std;
char a[1000][1000];
int n, m = 0, f = 0, h = 0;
int main() {
  cin >> n >> m;
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++) {
      cin >> a[i][j];
    }
  }
  if (n % 3 != 0 && m % 3 != 0) {
    cout << "NO";
    return 0;
  }
  if (n % 3 == 0 && m % 3 != 0) {
    for (int i = 1; i <= n / 3; i++) {
      for (int j = 1; j <= m; j++)
        if (a[i][j] != a[1][1]) f = 1;
    }
    for (int i = n / 3 + 1; i <= 2 * n / 3; i++) {
      for (int j = 1; j <= m; j++)
        if (a[i][j] != a[n / 3 + 1][1]) f = 1;
    }
    for (int i = 2 * n / 3 + 1; i <= n; i++) {
      for (int j = 1; j <= m; j++)
        if (a[i][j] != a[2 * n / 3 + 1][1]) f = 1;
    }
    if (a[1][1] == a[n / 3 + 1][1] || a[1][1] == a[n][1] ||
        a[n / 3 + 1][1] == a[n][1])
      f = 1;
    if (f == 0)
      cout << "YES";
    else
      cout << "NO";
    return 0;
  }
  if (n % 3 != 0 && m % 3 == 0) {
    for (int i = 1; i <= n; i++) {
      for (int j = 1; j <= m / 3; j++)
        if (a[i][j] != a[1][1]) f = 1;
    }
    for (int i = 1; i <= n; i++) {
      for (int j = m / 3 + 1; j <= 2 * m / 3; j++)
        if (a[i][j] != a[1][m / 3 + 1]) f = 1;
    }
    for (int i = 1; i <= n; i++) {
      for (int j = 2 * m / 3 + 1; j <= m; j++)
        if (a[i][j] != a[1][2 * m / 3 + 1]) f = 1;
    }
    if (a[1][1] == a[1][m / 3 + 1] || a[1][1] == a[1][m] ||
        a[1][m / 3 + 1] == a[1][m])
      f = 1;
    if (f == 0)
      cout << "YES";
    else
      cout << "NO";
    return 0;
  }
  for (int i = 1; i <= n / 3; i++) {
    for (int j = 1; j <= m; j++)
      if (a[i][j] != a[1][1]) f = 1;
  }
  for (int i = n / 3 + 1; i <= 2 * n / 3; i++) {
    for (int j = 1; j <= m; j++)
      if (a[i][j] != a[n / 3 + 1][1]) f = 1;
  }
  for (int i = 2 * n / 3 + 1; i <= n; i++) {
    for (int j = 1; j <= m; j++)
      if (a[i][j] != a[2 * n / 3 + 1][1]) f = 1;
  }
  for (int i = 1; i < n; i++) {
    for (int j = 1; j <= m / 3; j++)
      if (a[i][j] != a[1][1]) h = 1;
  }
  for (int i = 1; i <= n; i++) {
    for (int j = m / 3 + 1; j <= 2 * m / 3; j++)
      if (a[i][j] != a[1][m / 3 + 1]) h = 1;
  }
  for (int i = 1; i <= n; i++) {
    for (int j = 2 * m / 3 + 1; j <= m; j++)
      if (a[i][j] != a[1][2 * m / 3 + 1]) h = 1;
  }
  if (a[1][1] == a[n / 3 + 1][1] || a[1][1] == a[n][1] ||
      a[n / 3 + 1][1] == a[n][1])
    f = 1;
  if (a[1][1] == a[1][m / 3 + 1] || a[1][1] == a[1][m] ||
      a[1][m / 3 + 1] == a[1][m])
    h = 1;
  if (f == 0 || h == 0)
    cout << "YES";
  else
    cout << "NO";
  return 0;
}
