#include <bits/stdc++.h>
char s[50000];
char s1[50000], s2[50000];
int d(char c) {
  if (c >= '0' && c <= '9') return c - '0';
  if (c >= 'a' && c <= 'z') c = c - 'a' + 'A';
  return c - 'A' + 10;
}
bool judge(int base) {
  int a = 0, b = 0;
  for (int i = 0; i < strlen(s1); i++) {
    int temp = d(s1[i]);
    if (temp >= base) return false;
    a = a * base + temp;
  }
  for (int i = 0; i < strlen(s2); i++) {
    int temp = d(s2[i]);
    if (temp >= base) return false;
    b = b * base + temp;
  }
  if (a >= 0 && a < 24 && b >= 0 && b < 60) return true;
  return false;
}
void creat() {
  int n = strlen(s);
  int top = 0;
  int i;
  for (i = 0; i < n; i++) {
    if (s[i] == ':') break;
    if (s[i] == '0' && top == 0) continue;
    s1[top++] = s[i];
  }
  i++;
  if (top == 0) s1[top++] = '0';
  s1[top] = '\0';
  top = 0;
  for (; i < n; i++) {
    if (s[i] == '0' && top == 0) continue;
    s2[top++] = s[i];
  }
  if (top == 0) s2[top++] = '0';
  s2[top] = '\0';
}
void solve() {
  creat();
  if (strlen(s1) == 1 && strlen(s2) == 1) {
    if (d(s1[0]) < 24 && d(s1[0]) >= 0 && d(s2[0]) >= 0 && d(s2[0]) < 60)
      printf("-1\n");
    else
      printf("0\n");
    return;
  }
  bool first = false;
  for (int i = 1; i < 60; i++) {
    if (judge(i)) {
      if (!first) {
        first = true;
        printf("%d", i);
      } else
        printf(" %d", i);
    }
  }
  if (!first) printf("0");
  printf("\n");
}
int main() {
  while (gets(s)) {
    solve();
  }
}
