#include <bits/stdc++.h>
using namespace std;
const long double pi = 3.1415926535897932384626433832795;
const long double eps = 0.000000001;
const int INF = 1E9;
const int MAXN = 100000;
int ans, a[2], mn;
string s[2];
char c;
bool f[2];
int getn(char c) { return ('0' <= c && c <= '9') ? (c - '0') : (c - 'A' + 10); }
int main() {
  c = getchar();
  while (c != ':') {
    s[0] += c;
    c = getchar();
  }
  cin >> s[1];
  for (int k = 0; k < (int)(2); k++)
    for (int i = 0; i < (int)(s[k].size() - 1); i++)
      if (s[k][i] != '0') f[k] = 1;
  if (f[0] || f[1]) {
    f[0] = 1;
    for (int i = (int)(2); i <= (int)(60); i++) {
      f[1] = 1;
      for (int j = 0; j < (int)(2); j++) {
        mn = 1;
        a[j] = 0;
        for (int k = (int)(s[j].size()) - 1; k >= 0; k--) {
          if (getn(s[j][k]) >= i) f[1] = 0;
          a[j] += mn * getn(s[j][k]);
          mn *= i;
        }
      }
      if (f[1] && a[0] <= 23 && a[1] <= 59) {
        cout << i << ' ';
        f[0] = 0;
      }
    }
    if (f[0]) cout << 0 << endl;
  } else {
    if (getn(s[0][s[0].size() - 1]) <= 23)
      cout << -1;
    else
      cout << 0;
  }
  return 0;
}
