#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using tpl = tuple<int, int, int>;
using pcc = pair<char, char>;
const ll inf = 1e18 + 100;
const ll mod = 998244353;
int dr[] = {-1, 0, 1, 0};
int dc[] = {0, 1, 0, -1};
int kr[] = {-1, 1, -2, -2, -1, 1, 2, 2};
int kc[] = {-2, -2, -1, 1, 2, 2, -1, 1};
int dgr[] = {-1, -1, 1, 1};
int dgc[] = {1, -1, -1, 1};
const int N = 2e6;
int value(char ch) {
  if (isdigit(ch)) return ch - '0';
  return ch - 'A' + 10;
}
ll convert(string str, int b) {
  ll ans = 0, cur = 1;
  for (int i = str.size() - 1; i >= 0; i--) {
    ans += (value(str[i]) * cur);
    cur *= b;
  }
  return ans;
}
void solve() {
  string str, hour, minit;
  cin >> str;
  int len = str.size();
  int mx = 0, ok = 0;
  for (char ch : str) {
    if (ch == ':') {
      ok = 1;
      continue;
    }
    mx = max(mx, value(ch));
    if (ok) {
      minit += ch;
    } else {
      hour += ch;
    }
  }
  vector<ll> ans;
  ll H = 0, M = 0;
  for (int base = mx + 1; base <= N; base++) {
    H = convert(hour, base);
    M = convert(minit, base);
    if (H >= 24 or M >= 60) break;
    ans.push_back(base);
  }
  if (ans.size() > 1000000)
    printf("-1\n");
  else if (ans.size() == 0)
    printf("0\n");
  else {
    for (ll x : ans) printf("%lld ", x);
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int tt = 1;
  while (tt--) {
    solve();
  }
  return 0;
}
