You are given a broken clock. You know, that it is supposed to show time in 12- or 24-hours HH:MM format. In 12-hours format hours change from 1 to 12, while in 24-hours it changes from 0 to 23. In both formats minutes change from 0 to 59.

You are given a time in format HH:MM that is currently displayed on the broken clock. Your goal is to change minimum number of digits in order to make clocks display the correct time in the given format.

For example, if 00:99 is displayed, it is enough to replace the second 9 with 3 in order to get 00:39 that is a correct time in 24-hours format. However, to make 00:99 correct in 12-hours format, one has to change at least two digits. Additionally to the first change one can replace the second 0 with 1 and obtain 01:39.


-----Input-----

The first line of the input contains one integer 12 or 24, that denote 12-hours or 24-hours format respectively.

The second line contains the time in format HH:MM, that is currently displayed on the clock. First two characters stand for the hours, while next two show the minutes.


-----Output-----

The only line of the output should contain the time in format HH:MM that is a correct time in the given format. It should differ from the original in as few positions as possible. If there are many optimal solutions you can print any of them.


-----Examples-----
Input
24
17:30

Output
17:30

Input
12
17:30

Output
07:30

Input
24
99:99

Output
09:09

Difficulty: competition

Starter code:

Solutions:
n = int(input())
s = input().split(':')
if n == 12:
    if s[0] == '00':
        s[0] = '01'
    elif int(s[0]) > 12 and s[0][1] == '0':
        s[0] = '10'
    elif int(s[0]) > 12:
        s[0] = '0' + s[0][1]
else:
    if int(s[0]) > 23:
        s[0] = '0' + s[0][1]
if int(s[1]) > 59:
    s[1] = '0' + s[1][1]
print(':'.join(s))

form = int(input())
hs, ms = input().split(":")
if int(ms) > 59:
    ms = "0" + ms[1]
if form == 24:
    if int(hs) > 23:
        hs = "0" + hs[1]
else:
    if int(hs) > 12:
        if hs[1] == "0":
            hs = "10"
        else:
            hs = "0" + hs[1]
    elif int(hs) == 0:
        hs = "01"
print(hs + ":" + ms)

def best(h, n, x):
    best = ''
    bestCnt = 10
    begin = 0
    end = n
    if x == 'h':
        if n == 12:
            begin = 1
            end = 13
    for i in range(begin, end):
        si = str(i)
        if len(si) == 1:
            si = '0' + si
        bad = 0
        for x, y in zip(h, si):
            if x != y:
                bad += 1
        if bad < bestCnt:
            bestCnt = bad
            best = si
    return best

n = int(input())
s = input()
h = s[0:2]
m = s[3:5]
print(best(h, n, 'h'), best(m, 60, 'm'), sep=':')


#! /usr/bin/python
# kmwho



def solvecase():
    form   =  int(input().strip())
    hh,mm  = list(map(int,input().strip().split(":")))
    if mm > 59:
        mm = mm % 10
    if form == 24:
        if hh > 23:
            hh = hh % 10
    elif form == 12:
        if hh > 12:
            if hh % 10:
                hh = hh % 10
            else:
                hh = 10
        if hh == 0:
            hh = 1
    return "%02d:%02d" % (hh,mm)

def main():
	#solve()
	print(solvecase())


main()


n = int(input())
h, m = input().split(':')
ans = 1000
ans1 = ''
if n == 12:
    h1, m1 = '', ''
    for i in range(1, 13):
        for j in range(0, 60):
            h1 = (2 - len(str(i))) * '0' + str(i)
            m1 = (2 - len(str(j))) * '0' + str(j)
            cnt = 4
            if h1[0] == h[0]:
                cnt -= 1
            if h1[1] == h[1]:
                cnt -= 1
            if m1[0] == m[0]:
                cnt -= 1
            if m1[1] == m[1]:
                cnt -= 1
            if cnt < ans:
                ans = cnt
                ans1 = h1 + ':' + m1   
    print(ans1)
else:
    h1, m1 = '', ''
    for i in range(24):
        for j in range(0, 60):
            h1 = (2 - len(str(i))) * '0' + str(i)
            m1 = (2 - len(str(j))) * '0' + str(j)
            cnt = 4
            if h1[0] == h[0]:
                cnt -= 1
            if h1[1] == h[1]:
                cnt -= 1
            if m1[0] == m[0]:
                cnt -= 1
            if m1[1] == m[1]:
                cnt -= 1
            if cnt < ans:
                ans = cnt
                ans1 = h1 + ':' + m1  
    print(ans1)

c = input()
h, m = map(int, input().split(':'))
if m >= 60:
	m %= 10
if c == '12' and h == 0:
	h = 1
elif c == '12' and h > 12:
	if h % 10:
		h %= 10
	else:
		h = 10
elif c == '24' and h > 23:
	h %= 10
print('%02d:%02d' % (h,m))

def l(s1, s2):
	return len(list(i for i in range(len(s1)) if s1[i] != s2[i]))

c = int(input())

if c == 12:
	h = list(range(1, 13))
else:
	h = list(range(0, 24))


s = input()
min_s = ""
min_l = 100

for x in h:
	for y in range(60):
		new_s = "{0:02}:{1:02}".format(x,y)
		if l(s, new_s) < min_l:
			min_l = l(s, new_s)
			min_s = new_s

print(min_s)

n = int(input())
tm = tuple(map(int, input().split(':')))

cost = [[0 for i in range(100)] for j in range(100)]
for i in range(100):
    for j in range(100):
        x, y = i, j
        for k in range(2):
            cost[i][j] += (x % 10) != (y % 10)
            x //= 10
            y //= 10

hr_range = list(range(1, 13))
if n == 24:
    hr_range = list(range(0, 24))

best_time = None
best_val = 123
for h in hr_range:
    for m in range(60):
        cur = cost[h][tm[0]] + cost[m][tm[1]]
        if cur < best_val:
            best_val = cur
            best_time = '{:02d}:{:02d}'.format(h, m)

print(best_time)


__author__ = 'Alexander'
import sys
format = int(sys.stdin.readline().strip())
timeH, timeM = list(map(int,sys.stdin.readline().split(':')))
# print(format)
# print(timeH)
# print(timeM)
if format == 12:
    if timeH > 12 or timeH == 0:
        if timeH == 0: timeH = 1
        elif timeH%10 == 0: timeH = 10
        else: timeH %= 10
    if timeM > 59:
        timeM %= 10
else:
    if timeH > 23:
        timeH %= 10
    if timeM > 59:
        timeM %= 10
sys.stdout.write("%02d:%02d" % (timeH, timeM))