#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize("-Ofast")
#pragma GCC optimize("trapv")
#pragma GCC target( \
    "sse,sse2,sse3,ssse3,sse4,sse4.2,popcnt,abm,mmx,avx2,tune=native")
#pragma GCC optimize("-ffast-math")
#pragma GCC optimize("-funroll-loops")
#pragma GCC optimize("-funroll-all-loops,-fpeel-loops,-funswitch-loops")
const int N = 1e5 + 40;
const int MAXK = 12;
const long long int INF = 1000000000000000000;
const int RANDOM =
    chrono::high_resolution_clock::now().time_since_epoch().count();
long long int expo_pow(long long int x, long long int y) {
  if (y == 0) return 1;
  y = y % ((1000000007) - 1);
  x %= (1000000007);
  if (y == 0) y = (1000000007) - 1;
  long long int res = 1;
  while (y) {
    if (y & 1) res = (res * x) % (1000000007);
    x = (x * x) % (1000000007);
    y >>= 1;
  }
  return res;
}
long long int modInverse(long long int a, long long int m = (1000000007)) {
  return expo_pow(a, m - 2);
}
void solve() {
  string second;
  cin >> second;
  int ind;
  int cnt = 0;
  int mx = 0;
  map<char, int> m;
  for (char c = '0'; c <= '9'; c++) m[c] = c - '0';
  for (char c = 'A'; c <= 'Z'; c++) m[c] = c - 'A' + 10;
  for (int i = (0); i < ((int)second.size()); i++) {
    if (second[i] == ':') {
      ind = i;
    } else {
      mx = max(mx, m[second[i]]);
    }
    if (second[i] == '0') cnt++;
  }
  mx++;
  vector<int> ans;
  for (int i = (mx); i < (65); i++) {
    long long int ti = 1;
    long long int cur = 0;
    for (int j = (ind - 1); j > (-1); j -= 1) {
      cur += (m[second[j]]) * ti;
      ti *= i;
    }
    if (cur >= 24) break;
    cur = 0;
    ti = 1;
    for (int j = (second.size() - 1); j > (ind); j -= 1) {
      cur += (m[second[j]]) * ti;
      ti *= i;
    }
    if (cur > 59) break;
    ans.push_back(i);
    if (i == 60) {
      cout << -1 << '\n';
      return;
    }
  }
  if (ans.empty()) {
    cout << 0 << '\n';
  } else {
    for (auto x : ans) {
      cout << x << " ";
    }
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int T = 1;
  while (T--) {
    solve();
  }
}
