#include <bits/stdc++.h>
using namespace std;
bool Isvalid(char s[], int least) {
  int i = 0, sum = 0;
  while (s[i] != '\0' && s[i] != ':') {
    if (s[i] > '9')
      sum = sum * least + s[i] - 'A' + 10;
    else
      sum = sum * least + s[i] - '0';
    i++;
  }
  if (sum > 23) return false;
  i++;
  sum = 0;
  while (s[i] != '\0') {
    if (s[i] > '9')
      sum = sum * least + s[i] - 'A' + 10;
    else
      sum = sum * least + s[i] - '0';
    i++;
  }
  if (sum > 59) return false;
  return true;
}
int getmaxdig(char s[]) {
  int i = 0, pos = 0;
  while (s[i] != '\0') {
    if (s[i] != ':' && s[i] > s[pos]) {
      pos = i;
    }
    i++;
  }
  if (s[pos] > '9')
    return s[pos] - 'A' + 10;
  else
    return s[pos] - '0';
}
bool Isinfinted(char s[]) {
  int i = 0;
  while (s[i] == '0') i++;
  if (s[i] <= ('A' + 13) && s[i + 1] == ':' || s[i] == ':') {
    if (s[i] == ':')
      i++;
    else
      i += 2;
    while (s[i] == '0') i++;
    if (s[i + 1] == '\0' || s[i] == '\0') return true;
    return false;
  }
  return false;
}
int main() {
  char s[20];
  cin >> s;
  int maxdig = getmaxdig(s) + 1;
  if (Isinfinted(s))
    cout << "-1" << endl;
  else if (Isvalid(s, maxdig)) {
    for (; Isvalid(s, maxdig); maxdig++) cout << maxdig << " ";
    cout << endl;
  } else
    cout << "0" << endl;
  return 0;
}
