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