#include <bits/stdc++.h>
char arr[12], arr1[6], arr2[6];
void getstring() {
  int i = 0, j = 0, l1, l2, l, s;
  l = strlen(arr);
  while (arr[i] != ':') i++;
  s = i;
  i = 0;
  while (arr[i] == '0') {
    i++;
  }
  if (arr[i] == ':') {
    strcpy(arr1, "0");
  } else {
    while (arr[i] != ':') {
      arr1[j] = arr[i];
      i++;
      j++;
    }
    arr1[j] = '\0';
  }
  i = s + 1;
  while (arr[i] == '0' && i < l) {
    i++;
  }
  if (i == l) {
    strcpy(arr2, "0");
  } else {
    j = 0;
    while (i < l) {
      arr2[j] = arr[i];
      i++;
      j++;
    }
    arr2[j] = '\0';
  }
}
int getsum(char *arr, int Radix) {
  int l = strlen(arr);
  int j;
  double sum;
  j = 0;
  sum = 0;
  for (j = l - 1; j > -1; j--) {
    if (isdigit(arr[j])) {
      sum += (arr[j] - 48) * pow(Radix, l - 1 - j);
    } else if (isalpha(arr[j])) {
      sum += (arr[j] - 55) * pow(Radix, l - 1 - j);
    }
  }
  return sum;
}
int main() {
  int i, k, count, flag1, flag2, flag;
  gets(arr);
  i = 0;
  int Radix = 0;
  while (arr[i] != '\0') {
    if (isdigit(arr[i])) {
      if ((arr[i] - 48) > Radix) Radix = arr[i] - 48;
    } else if (isalpha(arr[i])) {
      if ((arr[i] - 55) > Radix) Radix = arr[i] - 55;
    }
    i++;
  }
  Radix++;
  getstring();
  flag = 0;
  if (strlen(arr1) == 1 && strlen(arr2) == 1) {
    if (isalpha(arr1[0])) {
      if (((arr1[0] - 55) > 24) || (((arr1[0] - 55) == 24) && arr2[0] != '0'))
        printf("0");
      else
        printf("-1");
    } else
      printf("-1");
  } else {
    while (1) {
      flag1 = getsum(arr1, Radix);
      flag2 = getsum(arr2, Radix);
      if (((flag1 <= 23) && (flag2 < 60))) {
        flag = 1;
        printf("%d ", Radix);
        Radix++;
      } else
        break;
    }
    if (flag == 0) printf("0");
  }
}
