#include <bits/stdc++.h>
using namespace std;
int main() {
  string s, hours, mins;
  cin >> s;
  int a = 1, b = 1, colon, i, radix = 0;
  for (i = 0; i < s.length(); i++) {
    if (s[i] == ':') {
      colon = i;
      break;
    }
  }
  for (i = 0; i < colon; i++) {
    if (s[i] != '0') {
      break;
    }
  }
  hours = s.substr(i, colon - i);
  for (i = colon + 1; i < s.length(); i++) {
    if (s[i] != '0') {
      break;
    }
  }
  mins = s.substr(i);
  if (hours.length() <= 1 and mins.length() <= 1) {
    hours.length() == 1 and hours[0] - 'A' + 10 >= 24 ? cout << 0 : cout << -1;
    return 0;
  }
  for (i = 0; i < s.length(); i++) {
    if (i != colon) {
      int cur = s[i] >= '0' and s[i] <= '9' ? s[i] - '0' : s[i] - 'A' + 10;
      radix = max(radix, cur);
    }
  }
  radix++;
  if (radix == 1) {
    radix = 2;
  }
  for (i = radix;; i++) {
    int HOURS = 0, MINS = 0;
    for (int j = 0; j < hours.length(); j++) {
      HOURS *= i;
      HOURS += hours[j] >= '0' and hours[j] <= '9' ? hours[j] - '0'
                                                   : hours[j] - 'A' + 10;
    }
    for (int j = 0; j < mins.length(); j++) {
      MINS *= i;
      MINS += mins[j] >= '0' and mins[j] <= '9' ? mins[j] - '0'
                                                : mins[j] - 'A' + 10;
    }
    if (HOURS <= 23 and MINS <= 59) {
      cout << i << " ";
    } else {
      if (i == radix) {
        cout << 0;
      }
      return 0;
    }
  }
}
