#include <bits/stdc++.h>
using namespace std;
char S[15];
int Sep, N, MaxD;
vector<int> Ans;
int Digit(int Pos) {
  return ('0' <= S[Pos] && S[Pos] <= '9' ? S[Pos] - '0' : S[Pos] - 'A' + 10);
}
int Nr(int Left, int Right, int Base) {
  int Ans = 0;
  for (int i = Left; i <= Right; ++i) Ans = Ans * Base + Digit(i);
  return Ans;
}
int main() {
  gets(S + 1);
  N = strlen(S + 1);
  for (int i = 1; i <= N; ++i)
    if (S[i] == ':') Sep = i;
  for (int i = 1; i <= N; ++i)
    if (i != Sep) MaxD = max(MaxD, Digit(i));
  for (int i = MaxD + 1;
       i <= 1000 && Nr(1, Sep - 1, i) < 24 && Nr(Sep + 1, N, i) < 60; ++i)
    Ans.push_back(i);
  if (Ans.size() > 100)
    printf("-1");
  else if (Ans.size() == 0)
    printf("0");
  else {
    for (int i = 0; i < Ans.size(); ++i) printf("%i ", Ans[i]);
  }
}
