#include <bits/stdc++.h>
using namespace std;
char s[12] = {0};
char a[6] = {0};
char b[6] = {0};
int min_base = 99999999;
int max_base = 0;
bool isLetter(char c) { return c >= 'A' && c <= 'Z' || c >= 'a' && c <= 'z'; }
bool isDigit(char c) { return c >= '0' && c <= '9'; }
int getVal(char c) {
  if (isDigit(c)) {
    return c - '0';
  } else {
    return (int)c - 55;
  }
}
int isValid(int base) {
  int i;
  int aVal = 0;
  for (i = 0; i < strlen(a); i++) {
    aVal +=
        (double)pow((double)base, (double)(strlen(a) - i - 1)) * getVal(a[i]);
  }
  if (aVal > 23) {
    return 0;
  }
  int bVal = 0;
  for (i = 0; i < strlen(b); i++) {
    bVal +=
        (double)pow((double)base, (double)(strlen(b) - i - 1)) * getVal(b[i]);
  }
  if (bVal > 59) {
    return 0;
  }
  return 1;
}
int main() {
  gets(s);
  int i, j, flag, lead0;
  j = 0;
  flag = 1;
  char min_ch = '0';
  lead0 = 1;
  for (i = 0; i < strlen(s); i++) {
    if (s[i] == ':') {
      flag = 0;
      j = 0;
      lead0 = 1;
      continue;
    }
    if (s[i] > min_ch) {
      min_ch = s[i];
    }
    if (flag) {
      if (lead0) {
        if (s[i] != '0') {
          a[j++] = s[i];
          lead0 = 0;
        }
      } else {
        a[j++] = s[i];
      }
    } else {
      if (lead0) {
        if (s[i] != '0') {
          b[j++] = s[i];
          lead0 = 0;
        }
      } else {
        b[j++] = s[i];
      }
    }
  }
  if (strlen(a) == 0) {
    a[0] = '0';
  }
  if (strlen(b) == 0) {
    b[0] = '0';
  }
  min_base = getVal(min_ch) + 1;
  if (strlen(a) == 1 && strlen(b) == 1) {
    if (getVal(a[0]) < 24 && getVal(b[0]) < 60) {
      cout << "-1" << endl;
      return 0;
    }
  }
  if (!isValid(min_base)) {
    cout << "0" << endl;
    return 0;
  } else {
    cout << min_base;
  }
  for (i = min_base + 1;; i++) {
    if (isValid(i)) {
      cout << " " << i;
    } else {
      break;
    }
  }
  cout << endl;
  return 0;
}
