#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  cin >> n >> m;
  char arr[n][m];
  set<char> ss;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      cin >> arr[i][j];
      ss.insert(arr[i][j]);
    }
  }
  bool isRow = n % 3 == 0;
  for (int i = 0; i < n; i++) {
    for (int j = 1; j < m; j++) {
      isRow &= (arr[i][j] == arr[i][j - 1]);
    }
  }
  int hOfS = n / 3;
  if (hOfS)
    for (int i = 0; i < n; i += hOfS) {
      for (int j = i + 1; j < i + hOfS && j < n; j++) {
        isRow &= arr[j][0] == arr[j - 1][0];
      }
    }
  bool iscol = m % 3 == 0;
  for (int j = 0; j < m; j++) {
    for (int i = 1; i < n; i++) {
      iscol &= arr[i][j] == arr[i - 1][j];
    }
  }
  int wOfS = m / 3;
  if (wOfS)
    for (int i = 0; i < m; i += wOfS) {
      for (int j = i + 1; j < i + wOfS && j < m; j++) {
        iscol &= arr[0][j] == arr[0][j - 1];
      }
    }
  if (ss.size() == 3 && (iscol || isRow)) {
    cout << "YES";
  } else {
    cout << "NO";
  }
  return 0;
}
