def ccc(s):
try:return int(s)
except:return ord(s)-ord("A")+10
q=input()
a,b=q.split(":")
a=a[::-1]
b=b[::-1]
def acc(p,q,b):
s=0
for i in range(len(p)):
if ccc(p[i])>=b:return False
s+=(b**i)*ccc(p[i])
if s>=24:return False
s=0
for i in range(len(q)):
if ccc(q[i])>=b:return False
s+=(b**i)*ccc(q[i])
if s>=60:return False
return True
c=0
if acc(a,b,100):
print(-1)
c=1
else:
for i in range(1,100):
if acc(a,b,i):
print(i,end=" ")
c+=1
if not c:print(0)
231A - Team | 479C - Exams |
1030A - In Search of an Easy Problem | 158A - Next Round |
71A - Way Too Long Words | 160A - Twins |
1A - Theatre Square | 1614B - Divan and a New Project |
791A - Bear and Big Brother | 1452A - Robot Program |
344A - Magnets | 96A - Football |
702B - Powers of Two | 1036A - Function Height |
443A - Anton and Letters | 1478B - Nezzar and Lucky Number |
228A - Is your horseshoe on the other hoof | 122A - Lucky Division |
1611C - Polycarp Recovers the Permutation | 432A - Choosing Teams |
758A - Holiday Of Equality | 1650C - Weight of the System of Nested Segments |
1097A - Gennady and a Card Game | 248A - Cupboards |
1641A - Great Sequence | 1537A - Arithmetic Array |
1370A - Maximum GCD | 149A - Business trip |
34A - Reconnaissance 2 | 59A - Word |