n = list(map(str,input().split())) n = list(n[0]) hour = str(n[0])+str(n[1]) other = str(n[2])+str(n[3])+str(n[4])+str(n[5])+str(n[6])+str(n[7]) if n[-2] == 'A': if hour < '12': time = hour+other print(time) else: a = '00' time = a+other print(time) else: hour = str(int(hour)+12) if hour > '23': hour = '12' time = hour+other else: time = hour+other print(time)