#include <bits/stdc++.h>
using namespace std;
int getdig(char ch) {
  if (ch >= '0' && ch <= '9')
    return ch - '0';
  else
    return ch - 'A' + 10;
}
int get(string str, int b) {
  reverse((str).begin(), (str).end());
  int po = 1, ret = 0, i;
  for (i = 0; i < (str.size()); i++) {
    int x = getdig(str[i]);
    if (x >= b) return -1;
    ret += po * x;
    po *= b;
  }
  return ret;
}
int main() {
  char h[100], m[100], str[100];
  int i;
  cin >> str;
  for (i = 0; i < (strlen(str)); i++) {
    if (str[i] == ':') str[i] = ' ';
  }
  sscanf(str, "%s %s", h, m);
  string hour = h;
  string min = m;
  pair<int, int> last;
  last.first = -1;
  last.second = -1;
  vector<int> v;
  int c = 0;
  for (i = 0; i < (100); i++) {
    if (get(hour, i) >= 0 && get(hour, i) <= 23)
      if (get(min, i) >= 0 && get(min, i) <= 59) {
        pair<int, int> now;
        now.first = get(hour, i);
        now.second = get(min, i);
        if (now.second != -1 && now.first != -1) {
          if (now == last) {
            c = 1;
            break;
          } else {
            last = now;
            v.push_back(i);
          }
        }
      }
  }
  if (v.size() == 0) {
    cout << 0 << endl;
  } else if (c == 1) {
    cout << -1 << endl;
  } else {
    for (i = 0; i < (v.size()); i++) {
      if (i) cout << " ";
      cout << v[i];
    }
    cout << endl;
  }
  return 0;
}
