#include <bits/stdc++.h>
using namespace std;
const int INF = 1000 * 1000 * 1000 + 7;
const double EPS = 1e-9;
int bit_count(int first) {
  return first == 0 ? 0 : 1 + bit_count(first & (first - 1));
}
inline int low_bit(int first) { return first & -first; }
inline int sign(double first) {
  return first < -EPS ? -1 : first > EPS ? 1 : 0;
}
inline int sign(int first) { return (first > 0) - (first < 0); }
int nextComb(int first) {
  if (!first) {
    fprintf(stderr, "nextComb(0) called\n");
    return ((1 << 30) - 1 + (1 << 30));
  }
  int smallest = first & -first;
  int ripple = first + smallest;
  int ones = first ^ ripple;
  ones = (ones >> 2) / smallest;
  return ripple | ones;
}
template <class T>
inline T gcd(T a, T b) {
  a = abs(a);
  b = abs(b);
  while (b) {
    int r = a % b;
    a = b;
    b = r;
  }
  return a;
}
template <class T>
inline T lcm(T a, T b) {
  return a / gcd(a, b) * b;
}
inline int getInt() {
  int a;
  return scanf("%d", &a) ? a : (fprintf(stderr, "trying to read\n"), -1);
}
inline double getDouble() {
  double a;
  return scanf("%lf", &a) ? a : (fprintf(stderr, "trying to read\n"), -1.0);
}
inline double myRand() {
  return ((double)rand() / RAND_MAX) + ((double)rand() / RAND_MAX / RAND_MAX);
}
inline string getLine() {
  string ret;
  getline(cin, ret, ':');
  return ret;
}
long long process(string s, int base) {
  long long ret = 0;
  for (int i = (int)0; i < (int)((int)(s).size()); ++i) {
    ret *= base;
    if (isdigit(s[i]))
      ret += s[i] - '0';
    else
      ret += s[i] - 'A' + 10;
  }
  return ret;
}
bool isValid(string s, int base) {
  for (int i = (int)0; i < (int)((int)(s).size()); ++i) {
    if (isdigit(s[i]) && s[i] - '0' >= base)
      return false;
    else if (s[i] - 'A' + 10 >= base)
      return false;
  }
  return true;
}
void myCode() {
  string hrs, mins;
  getline(cin, hrs, ':');
  getline(cin, mins);
  vector<int> ret;
  if (((int)(hrs).size()) < 6 && ((int)(mins).size()) < 7) {
    for (int i = (int)2; i < (int)100; ++i) {
      if (isValid(hrs, i) == true && isValid(mins, i) == true) {
        if (process(hrs, i) < 24 && process(mins, i) < 60) {
          ret.push_back(i);
        }
      }
    }
  }
  if (ret.empty())
    printf("0\n");
  else if (ret[((int)(ret).size()) - 1] == 99)
    printf("-1\n");
  else
    for (int i = (int)0; i < (int)((int)(ret).size()); ++i)
      printf("%d%c", ret[i], i == ((int)(ret).size()) - 1 ? '\n' : ' ');
}
int main() {
  srand(time(NULL));
  myCode();
  return 0;
}
