#include <bits/stdc++.h>
using namespace std;
map<char, int> m;
long long f(string r, int pos) {
  long long sum = 0;
  long long p = 1;
  for (int i = r.length() - 1; i >= 0; --i) {
    sum += m[r[i]] * p;
    p *= pos;
  }
  return sum;
}
int main() {
  string r = "", d = "";
  char t;
  while ((t = getchar()) != ':') {
    r += t;
  }
  cin >> d;
  int cnt = 1;
  m['0'] = 0;
  for (char i = '1'; i <= '9'; ++i) {
    m[i] = cnt;
    ++cnt;
  }
  for (char i = 'A'; i <= 'Z'; ++i) {
    m[i] = cnt;
    ++cnt;
  }
  int pos = 1;
  for (int i = 0; i < r.length(); ++i) {
    pos = max(pos, m[r[i]]);
  }
  for (int i = 0; i < d.length(); ++i) {
    pos = max(pos, m[d[i]]);
  }
  ++pos;
  if (f(r, pos) >= 24 || f(d, pos) >= 60) {
    cout << 0;
    return 0;
  }
  if (f(r, 100) == f(r, 150) && f(d, 100) == f(d, 150)) {
    cout << -1;
    return 0;
  }
  while (f(r, pos) < 24 && f(d, pos) < 60) {
    cout << pos << " ";
    ++pos;
  }
  return 0;
}
