#include <bits/stdc++.h>
using namespace std;
char a[22];
char b[22];
set<int> ans;
int upper[26];
int transtlate(char tar[], int i) {
  int len = strlen(tar);
  int temp = 1;
  int res = 0;
  for (int j = len - 1; j >= 0; j--) {
    if (isdigit(tar[j])) {
      if (tar[j] - '0' >= i) return -1;
      res += (tar[j] - '0') * temp;
    } else {
      int x = upper[tar[j] - 'A'];
      if (x >= i) return -1;
      res += x * temp;
    }
    temp *= i;
  }
  return res;
}
bool check(char x[], int flag) {
  int len = strlen(x);
  bool zero = true;
  if (len > 1)
    for (int i = len - 2; i >= 0; i--)
      if (x[i] != '0') {
        zero = false;
        break;
      }
  if (len == 1) {
    if (isdigit(x[len - 1]))
      return true;
    else if (flag == 0) {
      if (upper[x[len - 1] - 'A'] < 24)
        return true;
      else
        return false;
    } else
      return true;
  }
  if (zero) {
    if (isdigit(x[len - 1]))
      return true;
    else if (flag == 0 && upper[x[len - 1] - 'A'] < 24)
      return true;
    else if (flag == 1)
      return true;
    else
      return false;
  } else
    return false;
}
int main() {
  for (char i = 'A'; i <= 'Z'; i++) upper[i - 'A'] = i - 'A' + 10;
  scanf("%s", a);
  int cut;
  for (int i = 0; i < strlen(a); i++)
    if (a[i] == ':') {
      cut = i + 1;
      a[i] = '\0';
    }
  strcpy(b, a + cut);
  if (check(a, 0) && check(b, 1)) {
    cout << -1 << endl;
    return 0;
  }
  for (int i = 2; i <= 80; i++) {
    int a_10 = transtlate(a, i);
    int b_10 = transtlate(b, i);
    if (a_10 != -1 && b_10 != -1 && a_10 < 24 && b_10 < 60) ans.insert(i);
  }
  if (ans.size() == 0)
    cout << 0 << endl;
  else {
    set<int>::iterator it = ans.begin();
    for (it = ans.begin(); it != ans.end();) {
      cout << *it;
      it++;
      if (it != ans.end())
        cout << " ";
      else
        cout << endl;
    }
  }
  ans.clear();
  return 0;
}
