#include <bits/stdc++.h>
using namespace std;
char s1[10], s2[10];
int Get(char s[]) {
  int i = 0, Max = 0;
  char str[10] = {0};
  while (s[i] == '0') ++i;
  strcpy(str, s + i);
  strcpy(s, str);
  i = 0;
  while (s[i]) {
    int tmp = s[i];
    if (s[i] < 'A')
      tmp -= '0';
    else
      tmp = tmp - 'A' + 10;
    if (tmp > Max) Max = tmp;
    ++i;
  }
  return Max;
}
int judge(char s[], int r, int Max) {
  int p = 0, i = 0;
  while (s[i]) {
    if (s[i] < 'A')
      p = p * r + s[i++] - '0';
    else
      p = p * r + s[i++] - 'A' + 10;
  }
  if (p <= Max) return 1;
  return 0;
}
int main() {
  char ss[20];
  while (scanf("%s", ss) == 1) {
    memset(s1, 0, sizeof(s1));
    ;
    memset(s2, 0, sizeof(s2));
    ;
    int i = 0, j = 0;
    while (ss[i] != ':') s1[j++] = ss[i++];
    ++i, j = 0;
    while (ss[i]) s2[j++] = ss[i++];
    int Min = 0;
    Min = max(0, max(Get(s1), Get(s2)));
    if (strlen(s1) <= 1 && strlen(s2) <= 1 && Get(s1) <= 23 && Get(s2) <= 59) {
      puts("-1");
    } else {
      int f = 0;
      Min++;
      Min = max(2, Min);
      while (Min <= 60) {
        if (judge(s1, Min, 23) && judge(s2, Min, 59)) {
          printf(f++ == 0 ? "%d" : " %d", Min);
        }
        Min++;
      }
      if (!f) printf("0");
      puts("");
    }
  }
  return 0;
}
