IN = [int(x) for x in input().replace('[', '').replace(']', '').split(',')]
times = []
for a in range(6):
    for b in range(6):
        for c in range(6):
            for d in range(6):
                for e in range(6):
                    for f in range(6):
                        if a != b and a != c and a != d and a != e and a != f and b != c and b != d and b != e and b != f and c != d and c != e and c != f and d != e and d != f and e != f:
                            times.append([IN[a] * 10 + IN[b], IN[c] * 10 + IN[d], IN[e] * 10 + IN[f]])
res = [-1, -1, -1]

for each in times:
    hour = each[0]
    m = each[1]
    s = each[2]
    if hour < 24 and m < 60 and s < 60:
        if hour > res[0]:
            res[0] = hour
            res[1] = m
            res[2] = s
        elif hour == res[0] and m > res[1]:
            res[0] = hour
            res[1] = m
            res[2] = s
        elif hour == res[0] and m == res[1] and s > res[2]:
            res[0] = hour
            res[1] = m
            res[2] = s
if sum(res) == -3:
    print("invalid")
else:
    print(str(res[0]).zfill(2) + ':' + str(res[1]).zfill(2) + ':' + str(res[2]).zfill(2))