#include <bits/stdc++.h>
using namespace std;
bool check_single_row(vector<string> &s, long long int n, long long int m,
                      long long int x) {
  for (long long int i = 1; i < m; i++) {
    if (s[x][i] != s[x][i - 1]) return false;
  }
  return true;
}
bool check_single_col(vector<string> &s, long long int n, long long int m,
                      long long int x) {
  for (long long int i = 1; i < n; i++) {
    if (s[i][x] != s[i - 1][x]) return false;
  }
  return true;
}
bool check_row_wise(vector<string> &s, long long int n, long long int m) {
  if (n % 3 != 0) return false;
  long long int height = n / 3;
  set<char> c;
  c.insert(s[0][0]);
  c.insert(s[height][0]);
  c.insert(s[2 * height][0]);
  for (long long int i = 0; i < height; i++) {
    if (!check_single_row(s, n, m, i)) return false;
    if (i > 0) {
      for (long long int j = 0; j < m; j++) {
        if (s[i][j] != s[i - 1][j]) return false;
      }
    }
  }
  for (long long int i = height; i < 2 * height; i++) {
    if (!check_single_row(s, n, m, i)) return false;
    if (i > height) {
      for (long long int j = 0; j < m; j++) {
        if (s[i][j] != s[i - 1][j]) return false;
      }
    }
  }
  for (long long int i = 2 * height; i < n; i++) {
    if (!check_single_row(s, n, m, i)) return false;
    if (i > 2 * height) {
      for (long long int j = 0; j < m; j++) {
        if (s[i][j] != s[i - 1][j]) return false;
      }
    }
  }
  long long int sz = c.size();
  return sz == 3;
}
bool check_column_wise(vector<string> &s, long long int n, long long int m) {
  if (m % 3 != 0) return false;
  long long int width = m / 3;
  set<char> c;
  c.insert(s[0][0]);
  c.insert(s[0][width]);
  c.insert(s[0][2 * width]);
  for (long long int i = 0; i < width; i++) {
    if (!check_single_col(s, n, m, i)) return false;
    if (i > 0) {
      for (long long int j = 0; j < n; j++) {
        if (s[j][i] != s[j][i - 1]) return false;
      }
    }
  }
  for (long long int i = width; i < 2 * width; i++) {
    if (!check_single_col(s, n, m, i)) return false;
    if (i > width) {
      for (long long int j = 0; j < n; j++) {
        if (s[j][i] != s[j][i - 1]) return false;
      }
    }
  }
  for (long long int i = 2 * width; i < m; i++) {
    if (!check_single_col(s, n, m, i)) return false;
    if (i > 2 * width) {
      for (long long int j = 0; j < n; j++) {
        if (s[j][i] != s[j][i - 1]) return false;
      }
    }
  }
  long long int sz = c.size();
  return sz == 3;
}
void solve() {
  long long int n, m;
  cin >> n >> m;
  vector<string> s(n);
  for (long long int i = 0; i < n; i++) {
    cin >> s[i];
  }
  bool ok = false;
  ok |= check_row_wise(s, n, m);
  ok |= check_column_wise(s, n, m);
  if (ok)
    cout << "YES\n";
  else
    cout << "NO\n";
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  solve();
  return 0;
}
