#include <bits/stdc++.h>
char hour[10], minu[10];
int lenh, lenm;
int ok(int h, int m, int base) {
  int i;
  for (i = h; i < lenh; i++) {
    if ('0' <= hour[i] && hour[i] <= '9') {
      if (hour[i] - '0' >= base) return 0;
    } else {
      if (hour[i] - 'A' + 10 >= base) return 0;
    }
  }
  for (i = m; i < lenm; i++) {
    if ('0' <= minu[i] && minu[i] <= '9') {
      if (minu[i] - '0' >= base) return 0;
    } else {
      if (minu[i] - 'A' + 10 >= base) return 0;
    }
  }
  return 1;
}
int to_num(int p, char* str, int base) {
  int count = 0, tmp = 1, i, t, len;
  len = strlen(str);
  for (i = len - 1; i >= p; i--) {
    if ('0' <= str[i] && str[i] <= '9')
      t = str[i] - '0';
    else
      t = str[i] - 'A' + 10;
    count += t * tmp;
    tmp *= base;
  }
  return count;
}
void input() {
  char tmp;
  lenh = 0, lenm = 0;
  while (1) {
    scanf("%c", &tmp);
    if (('0' <= tmp && tmp <= '9') || ('A' <= tmp && tmp <= 'Z'))
      hour[lenh++] = tmp;
    if (tmp == ':') break;
  }
  while (scanf("%c", &tmp) != EOF) {
    if (('0' <= tmp && tmp <= '9') || ('A' <= tmp && tmp <= 'Z'))
      minu[lenm++] = tmp;
    if (tmp == ':') break;
  }
}
int main() {
  int ph, pm, base, flag;
  int nh, nm, i;
  input();
  ph = 0;
  flag = 0;
  lenh = strlen(hour);
  for (i = 0; i < lenh; i++)
    if (hour[i] != '0') break;
  ph = i;
  lenm = strlen(minu);
  for (i = 0; i < lenm; i++)
    if (minu[i] != '0') break;
  pm = i;
  if (lenh - ph <= 1 && lenm - pm <= 1) {
    if (hour[ph] >= 'O' && hour[ph] <= 'Z') {
      printf("0\n");
      return 0;
    }
    printf("-1\n");
    return 0;
  }
  for (base = 2;; base++) {
    if (ok(ph, pm, base)) {
      nh = to_num(ph, hour, base);
      nm = to_num(pm, minu, base);
      if (nh < 24 && nm < 60) {
        if (flag)
          printf(" %d", base);
        else
          printf("%d", base);
        flag = 1;
      } else
        break;
    }
  }
  if (!flag) printf("0\n");
  return 0;
}
