#include <bits/stdc++.h>
#pragma GCC optimize("O3")
const long long mod1 = 998244353;
const long long mod2 = 1000000007;
long long pow(int a, int b) {
  if (b == 0 || a == 1) return 1;
  if (b % 2 == 0) {
    long long k = pow(a, b / 2);
    return (k * k);
  } else {
    long long k = pow(a, b / 2);
    return k * k * a;
  }
}
long long powmod(long long a, long long b, long long mod) {
  if (b == 0 || a == 1) {
    if (mod == 1)
      return 0;
    else
      return 1;
  }
  if (b % 2 == 0) {
    long long k = powmod(a, b / 2, mod);
    return (k * k) % mod;
  } else {
    long long k = powmod(a, b / 2, mod);
    return ((k * k) % mod * a) % mod;
  }
}
long long gcd(long long a, long long b) {
  if (a == 0) return b;
  if (b == 0) return a;
  if (a > b)
    return gcd(a % b, b);
  else
    return gcd(b % a, a);
}
int prime(int p) {
  for (int i = 2; i * i <= p; i++) {
    if (p % i == 0 && i < p) return 0;
  }
  return 1;
}
long long sqr(long long i) { return i * i; }
using namespace std;
signed main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  string s1, s2, s;
  cin >> s;
  s1 = "";
  s2 = "";
  int qq = 0;
  for (int i = 0; i < s.size(); i++) {
    if (s[i] != ':' && qq == 0) s1 += s[i];
    if (s[i] != ':' && qq == 1) s2 += s[i];
    if (s[i] == ':') qq = 1;
  }
  int q = 0;
  while (s1.size() != 0 && s1[0] == '0') s1.erase(0, 1);
  while (s2.size() != 0 && s2[0] == '0') s2.erase(0, 1);
  int max1 = 0;
  for (int i = 0; i < s1.size(); i++) {
    if (s1[i] >= '0' && s1[i] <= '9')
      max1 = max(int(max1), s1[i] - '0');
    else
      max1 = max(max1, s1[i] - 'A' + 10);
  }
  if (max1 >= 24) {
    cout << "0";
    return 0;
  }
  for (int i = 0; i < s2.size(); i++) {
    if (s2[i] >= '0' && s2[i] <= '9')
      max1 = max(int(max1), s2[i] - '0');
    else
      max1 = max(max1, s2[i] - 'A' + 10);
  }
  if (s1.size() <= 1 && s2.size() <= 1) {
    cout << -1;
    return 0;
  }
  max1++;
  for (int i = max1; i <= 59; i++) {
    int a = 0;
    int cur = 1;
    for (int j = s1.size() - 1; j >= 0; j--) {
      if (s1[j] >= '0' && s1[j] <= '9')
        a += cur * (s1[j] - '0');
      else
        a += cur * (s1[j] - 'A' + 10);
      cur *= i;
    }
    int b = 0;
    cur = 1;
    for (int j = s2.size() - 1; j >= 0; j--) {
      if (s2[j] >= '0' && s2[j] <= '9')
        b += cur * (s2[j] - '0');
      else
        b += cur * (s2[j] - 'A' + 10);
      cur *= i;
    }
    if (a <= 23 && b <= 59) {
      cout << i << " ";
      q++;
    }
  }
  if (q == 0) cout << "0";
  return 0;
}
