#include <bits/stdc++.h>
int main() {
  char s[20];
  bool jizz = false;
  int value1[61] = {0}, value2[61] = {0}, k, max = 0;
  int m, n, a, b;
  scanf("%s", &s);
  for (m = 0; m < strlen(s); m++) {
    if (s[m] == ':') break;
    for (a = 2; a < 61; a++) {
      if (s[m] <= 'Z' && s[m] >= 'A')
        k = s[m] - 'A' + 10;
      else
        k = s[m] - '0';
      if (k > max) max = k;
      value1[a] = value1[a] * a + k;
    }
  }
  for (n = m + 1; n < strlen(s); n++) {
    for (a = 2; a < 61; a++) {
      if (s[n] <= 'Z' && s[n] >= 'A')
        k = s[n] - 'A' + 10;
      else
        k = s[n] - '0';
      if (k > max) max = k;
      value2[a] = value2[a] * a + k;
    }
  }
  if (value1[60] <= 23 && value2[60] <= 59)
    printf("-1\n");
  else {
    for (a = max + 1; a < 60; a++) {
      if (value1[a] <= 23 && value2[a] <= 59) {
        jizz = true;
        break;
      }
    }
    if (jizz == false) printf("0\n");
    for (a = max + 1; a < 60; a++) {
      if (value1[a] <= 23 && value2[a] <= 59) {
        printf("%d ", a);
      }
    }
  }
}
