#include <bits/stdc++.h>
using namespace std;
inline bool check(char flag[100][100], int n, int m) {
  int rows = 1;
  for (int i = 0; i < n - 1; ++i) {
    if (flag[i][0] == flag[i + 1][0]) {
      ++rows;
    } else {
      break;
    }
  }
  if (3 * rows != n) return false;
  if (flag[0][0] == flag[2 * rows][0] || flag[rows][0] == flag[2 * rows][0])
    return false;
  for (int i = 1; i < 3; ++i) {
    for (int j = 0; j < rows - 1; ++j) {
      if (flag[i * rows + j][0] != flag[i * rows + j + 1][0]) return false;
    }
  }
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < m - 1; ++j) {
      if (flag[i][j] != flag[i][j + 1]) return false;
    }
  }
  return true;
}
void test() {
  int n, m;
  scanf("%d %d\n", &n, &m);
  char flag[100][100];
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < m; ++j) {
      flag[i][j] = getchar();
    }
    getchar();
  }
  if (check(flag, n, m)) {
    printf("YES");
    return;
  }
  char flagt[100][100];
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < m; ++j) {
      flagt[j][i] = flag[i][j];
    }
  }
  if (check(flagt, m, n)) {
    printf("YES");
    return;
  }
  printf("NO");
}
int main() {
  int t = 1;
  while (t--) test();
  return 0;
}
