z=input
mod = 10**9 + 7
from collections import *
from queue import *
from sys import *
from collections import *
from math import *
from heapq import *
from itertools import *
from bisect import *
from collections import Counter as cc
from math import factorial as f
def lcd(xnum1,xnum2):
    return (xnum1*xnum2//gcd(xnum1,xnum2))

################################################################################

"""

n=int(z())

for i in range(int(z())):

for i in range(int(z())):

x=int(z())

l=list(map(int,z().split()))

a,b=map(int,z().split())

l=set(map(int,z().split()))

led=(6,2,5,5,4,5,6,3,7,6)

vowel={'a':0,'e':0,'i':0,'o':0,'u':0}

color-4=["G", "GB", "YGB", "YGBI", "OYGBI" ,"OYGBIV",'ROYGBIV' ]

"""

###########################---START-CODING---###############################################

for i in range(int(z())):
    x=int(z())
    l=[]
    j=1
    s=2
    d=100
    for i in range(1000,1000-x,-1):
        l.append(i)
    print(*l)


for _ in range(int(input())):
    n = int(input())
    x =  ["1"]
    if n == 1:
        print(1)
    else:
        for i in range(n):
            x.append(str(int(x[-1]) + 2))
        print(" ".join(x))


for _ in range(int(input())):
    n = int(input())
    x =  ["1"]
    if n == 1:
        print(1)
    else:
        x = "1 " * n
        print(x[:-1])


for _ in range(int(input())):
    n = int(input())
    x=  ["1", "2"]
    if n == 1:
        print(1)
    else:
        for i in range(n-2):
            x.append(str(int(x[-1]) + int(x[-2]) + 1))
        print(" ".join(x))


for _ in range(int(input())):
    n = int(input())
    x =  ["1"]
    if n == 1:
        print(1)
    else:
        for i in range(n-1):
            x.append(str(int(x[-1]) + 2))
        print(" ".join(x))


for _ in range(int(input())):
    n = int(input())
    x=  ["0", "1"]
    if n == 1:
        print(1)
    else:
        for i in range(n-2):
            x.append(str(int(x[-1]) + int(x[-2]) + 1))
        print(" ".join(x))


def solve():
	n=int(input())
	for i in range(n):
		print(1)
t = int(input())
while(t>0):
	solve()
	t=t-1


t = int(input())
for _ in range(t):
    n = int(input())
    print(*([1]*n))


t=int(input())
while(t>0):
	n=int(input())
	for i in range(n):
		print(1,)
	t=t-1


def solve():
	n = int(input())
	for i in range(n):
		print(1)
t = int(input())
while(t>0):
	solve()
	t=t-1


t=int(input())
while(t>0):
	n=int(input())
	for i in range(n):
		print(1,end=" ")
	t=t-1


for _ in range(int(input())):
    n=int(input())
    a=[1000-n-1]+[1]*(n-1)
    for i in a:
        print(i,end=' ')
    print()


for _ in range(int(input())):
    n=int(input())
    a=[1000//n]*n+[1000%n]*(1)
    for i in a:
        print(i,end=' ')
    print()


for _ in range(int(input())):
    n=int(input())
    a=[1000//n]*(n)
    for i in a:
        print(i,end=' ')
    print()


for _ in range(int(input())):
    n=int(input())
    l=[i for i in range(1,2*n,2)]
    print(' '.join(map(str,l)))


for _ in range(int(input())):
    n=int(input())
    l=[1]*n
    print(' '.join(map(str,l)))


for _ in range(int(input())):
    l=[1,2,4,5]
    n=int(input())
    if n>4:
        for i in range(n-4):
            l.append(l[-1]+3)
    print(' '.join(map(str,l)))


test = int(input())
while(test>0):
    n = int(input())
    for i in range(n):
        print(1,end=" ")
    test-=1


test = int(input())
while(test>0):
    n = int(input())
    for i in range(n):
        print(2)
    test-=1


n = int(input())
for i in range(n):
    num = int(input())
    for j in range(num):
        print(1,end=" ")
    print()


test = int(input())
while(test>0):
    n = int(input())
    arr = [ ]
    for i in range(n):
        arr.append(1)
        print(arr[i],end=" ")
    test-=1


test = int(input())
while(test>0):
    n = int(input())
    num = 1
    for i in range(n):
        print(num+i,end=" ")
        num+=1
    test-=1


n = int(input())
for i in range(n):
    num = int(input())
    for j in range(num):
        print(1,end=" ")


for _ in range(int(input())):
    n=int(input())
    for i in range(n):
        print('1',end=' ')
    print()


for _ in range(int(input())):
    n=int(input())
    for i in range(1000,1000-n):
        print(i,end=' ')


for _ in range(int(input())):
    n=int(input())
    for i in range(1000,1000-n,-1):
        print(i,end=' ')
    print()


for _ in range(int(input())):
    n=int(input())
    for i in range(1000,1000-n,-1):
        print(i,end=' ')


t = int(input())
result = []
for i in range(t):
  n = int(input())
  result.append(' '.join([str(1) for e in range(n)]))

for m in result:
  print(m)


t = int(input())
result = []
for i in range(t):
  n = int(input())
  result.append(' '.join([1 for e in range(n)]))

for m in result:
  print(m)


t = int(input())
result = []
for i in range(t):
  n = int(input())
  result.append(' '.join([(int(e)-int(e)+1 for e in range(n)]))

for m in result:
  print(m)


for _ in range(int(input())):
    n = int(input())
    lol = 1
    for i in range(n):
        print(lol,end=" ")
        lol = lol + 1 + lol
    print()


for _ in range(int(input())):
    n = int(input())
    lol = 1
    for i in range(n):
        print(lol,end=" ")
        lol = lol + 2
    print()


for _ in range(int(input())):
    n = int(input())
    for i in range(n):
        print(3,end=" ")
    print()


from sys import stdin

def input(): return stdin.readline()

T = int(input())
for _ in range(T):
    n = int(input())
    an = ""
    for _ in range(n):
        an += "1 "
    print(an.strip())


from sys import stdin

def input(): return stdin.readline()

T = int(input())
for _ in range(T):
    n = int(input())
    for _ in range(n):
        print(1, end=" ")
    print("\n")


from sys import stdin

def input(): return stdin.readline()

T = int(input())
for _ in range(T):
    n = int(input())
    for _ in range(n):
        print(1, end=" ")


t = int(input())

for i in range(t) :
    n = int(input())
    # total = 1
    a = []
    for j in range(n) :
        if j % 2 == 0 :
            a.append(1)
        else :
            a.append(5)

    print(*a)


t = int(input())

for i in range(t) :
    n = int(input())
    total = 1
    a = []
    for j in range(n) :
        if total <= 1000 :
            a.append(total + 1)
            total += a[j]
        else :
            total -= a[j-1]
            a.append(total - 1)
        print(a[j])


t = int(input())

for i in range(t) :
    n = int(input())
    total = 1
    a = []
    for j in range(n) :
        if total <= 1000 :
            a.append(total + 1)
            total += a[j]
        else :
            total -= a[j-1]
            a.append(total - 1)

    print(*a)


t=int(input())
for ty in range(t):
	n=int(input())
	for j in range(n):
		print(1,end=' ')


t=int(input())
for ty in range(t):
	n=int(input())
	for j in range(n):
		print(i,end=' ')


t=int(input())
for ty in range(t):
	n=int(input())
	for j in range(n-1):
		print(1,end=' ')
	print(1)


l=int(input())
for i in range(l):
    n=int(input())
    for i in range(n):
        print("1 ",end="")
    print()


a = int(input())
for i in range(0,a) :
    b = int(input())
    l = [1]*b
    print(l)


a = int(input())
for i in range(0,a):
    b = int(input())
    for o in range(0,b) :
        print(1)


a = int(input())
for i in range(0,a) :
    b = int(input())
    for i in range(0,b) :
        print(int(1))


for _ in range(int(input())):
    n = int(input())
    a = [1]*n
    print(*a)


for _ in range(int(input())):
    n = int(input())
    ans = []
    if n%2==0:
        for i in range(0,n//2):
            ans.append(2*i+1)
            ans.append(2*i+1)
    else:
        for i in range(0,n//2):
            ans.append(2*i+1)
            ans.append(2*i+1)
        i+=1
        ans.append(2*i+1)
    print(*ans)


for _ in range(int(input())):
    n = int(input())
    ans = []
    if n%2==0:
        for i in range(0,n//2):
            ans.append(2*i+1)
            ans.append(2*i+1)
    else:
        for i in range(0,n//2):
            ans.append(2*i+1)
            ans.append(2*i+1)
        if ans: ans.append(ans[-1]+2)
        else: ans.append(1)
    print(*ans)


for _ in range(int(input())):
    n = int(input())
    ans = []
    if n%2==0:
        for i in range(0,n//2):
            ans.append(2*i+1)
            ans.append(2*i+1)
    else:
        for i in range(0,n//2):
            ans.append(2*i+1)
            ans.append(2*i+1)
        i+=1
        ans.append(2*i+1)
    print(*ans)

for _ in range(int(input())):
    n = int(input())
    ans = []
    if n%2==0:
        for i in range(0,n//2):
            ans.append(2*i+1)
            ans.append(2*i+1)
    else:
        for i in range(0,n//2):
            ans.append(2*i+1)
            ans.append(2*i+1)
        i+=1
        ans.append(2*i+1)
    print(*ans)


#include<stdio.h>
int main()
{

	int type,hr,min,i;

	scanf("%d",&type);
	scanf("%02d:%02d",&hr,&min);
	if(hr==0)
		hr=1;

	 if(min==60)
		 min=0;
		 else if(min>60)
		min=min%10;
	if(type==12)
	{
		if(hr>12)
			hr=hr%10;
		if(hr==0)
			hr=10;
	}
		else
		{
			if(hr>23)
				hr=hr%10;
			}

	printf("%02d:%02d",hr,min);
				return 0;
}


#include<stdio.h>
int main()
{

	int type,hr,min,i;

	scanf("%d",&type);
	scanf("%.2d:%.2d",&hr,&min);
	if(hr==0)
		hr=1;
//	if(min==0)
//		min=1;
	if(min>60)
		min=min%10;
	if(type==12)
		if(hr>12)
			hr=hr%10;

		else
			if(hr>24)
				hr=hr%10;
	printf("%.2d:%.2d",hr,min);
				return 0;
}


#include<stdio.h>
int main()
{

	int type,hr,min,i;

	scanf("%d",&type);
	scanf("%02d:%02d",&hr,&min);
	if(hr==0)
		hr=1;
//	if(min==0)
//		min=1;
	 if(min==60)
		 min=0;
		 else if(min>60)
		min=min%10;
	if(type==12)
	{
		if(hr>12)
			hr=hr%10;
	}
		else
		{
			if(hr>24)
				hr=hr%10;
			}
	printf("%02d:%02d",hr,min);
				return 0;
}


#include <stdio.h>

int main(void)
{
    int n;
    int hh,mm;

    scanf("%d",&n);
    scanf("%d:%d", &hh, &mm);

    if( n == 12)
    {
        while(hh<1)
            hh+=10;
        while(hh>12)
            hh-=10;
        while(mm>=60)
            mm-=60;
    }
    else if( n == 24)
    {
        while(hh<0)
            hh+=10;
        while(hh>23)
            hh-=10;
        while(mm>=60)
            mm-=60;
    }
    else
        return 0;

    if(hh<10 && mm<10)
        printf("0%d:0%d",hh,mm);
    else if(mm<10)
        printf("%d:0%d",hh,mm);
    else if(hh<10)
        printf("0%d:%d",hh,mm);
    else
        printf("%d:%d",hh,mm);

    system("pause");
    return 0;
}


#include <stdio.h>

int main(void)
{
    int n;
    int hh,mm;

    scanf("%d",&n);
    scanf("%d:%d", &hh, &mm);

    if( n == 12)
    {
        while(hh<1)
            hh+=10;
        while(hh>12)
            hh-=10;
        while(mm>=60)
            mm-=60;
    }
    else if( n == 24)
    {
        while(hh<0)
            hh+=10;
        while(hh>23)
            hh-=10;
        while(mm>=60)
            mm-=60;
    }
    else
        return 0;

    if(hh<10 && mm<10)
        printf("0%d:0%d",hh,mm);
    else if(mm<10)
        printf("%d:0%d",hh,mm);
    else if(hh<10)
        printf("0%d:%d",hh,mm);
    else
        printf("%d:%d",hh,mm);

    return 0;
}


/* Problem: 722A - Broken Clock */
/* Solver: Gusztav Szmolik */

#include <stdio.h>
#include <string.h>
#include <ctype.h>

int main ()
    {
    unsigned short tf;
    unsigned char tm[7];
    unsigned short h;
    unsigned short m;

    if (scanf("%hu",&tf) != 1)
        return -1;
    if (tf != 12 && tf != 24)
        return -1;
    if (scanf("%6s",tm) != 1)
        return -1;
    if (strlen(tm) != 5)
        return -1;
    if (!isdigit(tm[0]) || !isdigit(tm[1]) || !isdigit(tm[3]) || !isdigit(tm[4]))
        return -1;
    if (tm[2] != ':')
        return -1;
    h = 10*(tm[0]-'0')+tm[1]-'0';
    m = 10*(tm[3]-'0')+tm[4]-'0';
    if (tf == 12 && !h)
        printf ("01:");
    else if (tf == 12 && h > 12)
        {
        if (tm[1] == '0')
            printf ("10:");
        else
            printf ("0%c:",tm[1]);
        }
    else if (tf == 24 && h > 23)
        printf ("0%c:",tm[1]);
    else
        printf ("%c%c:",tm[0],tm[1]);
    if (m > 59)
        printf ("0%c\n",tm[4]);
    else
        printf ("%c%c\n",tm[3],tm[4]);
    return 0;
    }


#include <stdio.h>
#include <stdlib.h>

int main(void)
{
    int format;
    char hh[3], mm[3];
    scanf("%d\n", &format);
    hh[0]=getchar();
    hh[1]=getchar();
    getchar();
    mm[0]=getchar();
    mm[1]=getchar();
    hh[2]='\0';
    mm[2]='\0';
    int m=atoi(mm), h=atoi(hh);
    if(m>59)
        mm[0]='0';
    if(format==12)
        if(h<1 || h>12)
            if(h==0)
                hh[1]='1';
            else
                hh[0]='0';
    if(format==24)
        if(h>23)
            hh[0]='0';
    printf("%s:%s\n", hh, mm);

    return 0;
}


#include <stdio.h>
#include <stdlib.h>

int main(void)
{
    int format;
    char hh[3], mm[3];
    scanf("%d\n", &format);
    hh[0]=getchar();
    hh[1]=getchar();
    getchar();
    mm[0]=getchar();
    mm[1]=getchar();
    hh[2]='\0';
    mm[2]='\0';
    int m=atoi(mm), h=atoi(hh);
    if(m>59)
        mm[0]='0';
    if(format==12)
        if(h<1 || h>12)
            if(h==0)
                hh[1]='1';
            else if(h%10==0)
                hh[0]='1';
            else
                hh[0]='0';
    if(format==24)
        if(h>23)
            hh[0]='0';
    printf("%s:%s\n", hh, mm);

    return 0;
}


#include <stdio.h>
#include <string.h>

int main()
{
	//freopen ("lel.in","r",stdin);

int format;
int h,m;
char time[100];
scanf("%d",&format);
fflush(stdin);
gets(time);
sscanf(time,"%2d%*c%2d",&h,&m);

if(format==24)
{
	if(h>23)
	time[0]='0';

	if(m>59)
	  time[3]='3';

}
else if(format==12)
{
	if(time[0]>=1 && h>12)
	time[0]='0';
	if(m>59)
	  time[3]='3';

}

puts(time);

	return 0;
}


#include <stdio.h>
#include <string.h>

int main()
{
	//freopen ("lel.in","r",stdin);

int format;
int h,m;
char time[100];
scanf("%d",&format);
fflush(stdin);
gets(time);
sscanf(time,"%2d%*c%2d",&h,&m);

if(format==24)
{
	if(h>23)
	time[0]='0';

	if(m>59)
	  time[3]='3';

}
else if(format==12)
{
	if(time[0]>=1 && h>12)
	time[0]='0';
	if(m>59)
	  time[3]='3';

}

printf("%s",time);

	return 0;
}


#include <stdio.h>
#include <string.h>

int main()
{
	//freopen ("lel.in","r",stdin);

int format;
int h,m;
char time[100];
scanf("%d",&format);
fflush(stdin);
gets(time);
sscanf(time,"%2d%*c%2d",&h,&m);

if(format==24)
{
	if(h>23)
	time[0]='0';

	if(m>59)
	  time[3]='3';

}
else if(format==12)
{
	if(time[0]>=1 && h>12)
	time[0]='0';
	if(m>59)
	  time[3]='3';

}
sscanf(time,"%2d%*c%2d",&h,&m);
printf("%.2d:%2d",h,m);

	return 0;
}


#include <stdio.h>
#include <string.h>

int main()
{
	//freopen ("lel.in","r",stdin);

int format;
int h,m;
scanf("%d",&format);
scanf("%2d:%2d",&h,&m);

if(format==24)
{
	if(h>23)
	h=h%10;
	if(m>59)
	  m=m%10;

}
else if(format==12)
{    if(h==0)
 h=1;
	if(h>12 && h%10!=0)
	h=h%10;
	else h=10;
	if(m>59)
	  m=m%10;

}

printf("%.2d:%.2d",h,m);

	return 0;
}


#include <stdio.h>
#include <string.h>

int main()
{
	//freopen ("lel.in","r",stdin);

int format;
int h,m;
scanf("%d",&format);
scanf("%2d:%2d",&h,&m);

if(format==24)
{
	if(h>23)
	h=h%10;
	if(m>59)
	  m=m%10;

}
else if(format==12)
{    if(h==0)
 h=1;
	if(h>12 && h%10!=0)
	h=h%10;
	else if(h>12) h=10;
	if(m>59)
	  m=m%10;

}

printf("%.2d:%.2d",h,m);

	return 0;
}


#include <stdio.h>

int main()
{
	//freopen ("lel.in","r",stdin);

int format;
int h,m;
char time[100];
scanf("%d",&format);
fflush(stdin);
gets(time);
sscanf(time,"%2d%*c%2d",&h,&m);

if(format==24)
{
	if(h>23)
	time[0]='0';

	if(m>59)
	  time[3]='3';

}
else if(format==12)
{
	if(time[0]>=1 && h>12)
	time[0]='0';
	if(m>59)
	  time[3]='3';

}

puts(time);

	return 0;
}


#include <stdio.h>
#include <string.h>

int main()
{
	//freopen ("lel.in","r",stdin);

int format;
int h,m;
scanf("%d",&format);
scanf("%2d:%2d",&h,&m);

if(format==24)
{
	if(h>23)
	h=h%10;
	if(m>59)
	  m=m%10;

}
else if(format==12)
{    if(h==0)
 h=1;
	if(h>12)
	h=h%10;
	if(m>59)
	  m=m%10;

}

printf("%.2d:%.2d",h,m);

	return 0;
}


#include <stdio.h>
#include <string.h>

int main()
{
	//freopen ("lel.in","r",stdin);

int format;
int h,m;
scanf("%d",&format);
scanf("%2d:%2d",&h,&m);

if(format==24)
{
	if(h>23)
	h=h%10;
	if(m>59)
	  m=m%10;

}
else if(format==12)
{    if(h==0)
 h=1;
	if(h>12 && h%10!=0)
	h=h%10;
	else if(h>10) h=10;
	if(m>59)
	  m=m%10;

}

printf("%.2d:%.2d",h,m);

	return 0;
}


#include <stdio.h>
#include <string.h>

int main()
{
	//freopen ("lel.in","r",stdin);

int format;
int h,m;
scanf("%d",&format);
scanf("%2d:%2d",&h,&m);

if(format==24)
{
	if(h>23)
	h=h%10;
	if(m>59)
	  m=m%10;

}
else if(format==12)
{    if(h==0)
 h=1;
	if(h>12)
	h=h%10;
	if(m>59)
	  m=m%10;
	  if(h==0)
	  h=1;

}

printf("%.2d:%.2d",h,m);

	return 0;
}


#define _CRT_SECURE_NO_WARNINGS
#include <stdlib.h>
#include <stdio.h>
int main()
{
	int m;
	char s[100];
	int hour=0, min = 0;
	scanf("%d", &m);
	scanf("%s", s);
	hour = 10 * (s[0] - '0') + s[1] - '0';
	min = 10 * (s[3] - '0') + s[4] - '0';
	if (m == 24) {
		if (hour > 23)
			hour %=10;
		if (min > 59)
			min %= 10;
	}
	else
	{
		if (hour > 12 && hour % 10 != 0)
			hour %= 10;
		if (hour > 12 && hour % 10 == 0)
			hour = 10;
		if (hour == 0)
			hour = 1;
		if (min > 59)
			min %= 10;
	}
	if (hour < 10)
		printf("0%d", hour);
	else
		printf("%d", hour);
	printf(":");
	if (min < 10)
		printf("0%d", min);
	else
		printf("%d", min);
//	system("pause");
	return 0;
}


import java.util.Scanner;

public class a {

	public static void main(String[] args) {
	Scanner i = new Scanner(System.in);
	int f = i.nextInt();
	if(f==12)
	{
	Scanner in = new Scanner(System.in);
	String Str1 = in.nextLine();

    char[] Str2 = new char[100];
    char[] Str3 = new char[100];
    char[] Str4 = new char[100];
    char[] Str5 = new char[100];

       Str1.getChars(0, 2, Str2, 0);
       //System.out.println(Str2 );
       Str1.getChars(3, 5, Str3, 0);
       //System.out.println(Str3 );

       if(Str2[0]=='0')
       {
    	   Str4 = Str2;
       }
       else if(Str2[0]!='0')
       {
    	   Str4[0] = '0';
           Str4[1] = Str2[1];
       }
       int number = Integer.parseInt(String.valueOf(Str3));
       if(number>59)
       {
    	   Str5[0] = '0';
    	   Str5[1] = Str3[1];
       }
       else
       {
    	   Str5= Str3;
       }
       System.out.print(Str4[0]);
       System.out.print(Str4[1]);
       System.out.print(":");
       System.out.print(Str5[0]);
       System.out.print(Str5[1]);

	}
	else if(f==24)
	{
		Scanner inp = new Scanner(System.in);
		String Str1 = inp.nextLine();

	    char[] Str2 = new char[2];
	    char[] Str3 = new char[2];
	    char[] Str4 = new char[2];
	    char[] Str5 = new char[2];

	       Str1.getChars(0, 2, Str2, 0);
	       //System.out.println(Str2 );
	       Str1.getChars(3, 5, Str3, 0);
	       //System.out.println(Str3 );

	       if(Str2[0]=='0'||Str2[0]=='1')
	       {
	    	   Str4 = Str2;
	       }
	       else if(Str2[0]=='2')
	       {
	    	   Str4[0] = Str2[0];
	    	   int n1 = Integer.parseInt(String.valueOf(Str2[1]));
	    	   if(n1>3){
	    		   Str4[1]='0';
	    	   }
	    	   else
	    		   Str4[1]=Str2[1];

	       }
	       else if(Str2[0]!='0'&&Str2[0]!='1'&&Str2[0]!='2')
	       {
	    	   Str4[0] = '0';
	    	   Str4[1] = Str2[1];
	       }
	       int n3 = Integer.parseInt(String.valueOf(Str3));
	       if(n3>59)
	       {
	    	   Str5[0] = '0';
	    	   Str5[1] = Str3[1];
	       }
	       else
	       {
	    	   Str5= Str3;
	       }
	       System.out.print(Str4[0]);
	       System.out.print(Str4[1]);
	       System.out.print(":");
	       System.out.print(Str5[0]);
	       System.out.print(Str5[1]);

		}

	}

	}


import java.util.Scanner;

public class a {

	public static void main(String[] args) {
		Scanner in=new Scanner(System.in);
		int n=in.nextInt();
		if(n==12)
		{
		String s = in.next();
		String a[]=s.split(":");

		int b1=Integer.valueOf(a[0]);
		int b2=Integer.valueOf(a[1]);

       if(b1>12)
       {
    	   b1  = b1 % 10;
       }
       if(b1==0)b1 = 1;

       if(b2>59)
       {
    	   b2 = b2%10;
       }
       if(b1<10&&b2<10){
      System.out.print(0);
       System.out.print(b1);
       System.out.print(":");
       System.out.print(0);
       System.out.print(b2);
       }
       if(b1>=10&&b2>=10){
    	      //System.out.print(0);
    	       System.out.print(b1);
    	       System.out.print(":");
    	       //System.out.print(0);
    	       System.out.print(b2);
    	       }
       if(b1<10&&b2>=10){
    	      System.out.print(0);
    	       System.out.print(b1);
    	       System.out.print(":");
    	       //System.out.print(0);
    	       System.out.print(b2);
    	       }
       if(b1>=10&&b2<10){
    	      //System.out.print(0);
    	       System.out.print(b1);
    	       System.out.print(":");
    	       System.out.print(0);
    	       System.out.print(b2);
    	       }

	}
		if(n==24)
		{
			String s = in.next();
			String a[]=s.split(":");

			int b1=Integer.valueOf(a[0]);
			int b2=Integer.valueOf(a[1]);

	       if(b1>23)
	       {
	    	   b1  = b1 % 10;
	       }

	       if(b2>59)
	       {
	    	   b2 = b2%10;
	       }

	       if(b1<10&&b2<10){
	    	      System.out.print(0);
	    	       System.out.print(b1);
	    	       System.out.print(":");
	    	       System.out.print(0);
	    	       System.out.print(b2);
	    	       }
	    	       if(b1>=10&&b2>=10){
	    	    	      //System.out.print(0);
	    	    	       System.out.print(b1);
	    	    	       System.out.print(":");
	    	    	       //System.out.print(0);
	    	    	       System.out.print(b2);
	    	    	       }
	    	       if(b1<10&&b2>=10){
	    	    	      System.out.print(0);
	    	    	       System.out.print(b1);
	    	    	       System.out.print(":");
	    	    	       //System.out.print(0);
	    	    	       System.out.print(b2);
	    	    	       }
	    	       if(b1>=10&&b2<10){
	    	    	      //System.out.print(0);
	    	    	       System.out.print(b1);
	    	    	       System.out.print(":");
	    	    	       System.out.print(0);
	    	    	       System.out.print(b2);
	    	    	       }

		}
	}
}


import java.util.Scanner;

public class a {

	public static void main(String[] args) {
		Scanner in=new Scanner(System.in);
		int n=in.nextInt();
		if(n==12)
		{
		String s = in.next();
		String a[]=s.split(":");

		int b1=Integer.valueOf(a[0]);
		int b2=Integer.valueOf(a[1]);

       if(b1>12)
       {
    	   b1  = b1 - 10;
       }

       if(b2>59)
       {
    	   b2 = b2%10;
       }
       if(b1<10&&b2<10){
      System.out.print(0);
       System.out.print(b1);
       System.out.print(":");
       System.out.print(0);
       System.out.print(b2);
       }
       if(b1>10&&b2>10){
    	      //System.out.print(0);
    	       System.out.print(b1);
    	       System.out.print(":");
    	       //System.out.print(0);
    	       System.out.print(b2);
    	       }
       if(b1<10&&b2>10){
    	      System.out.print(0);
    	       System.out.print(b1);
    	       System.out.print(":");
    	       //System.out.print(0);
    	       System.out.print(b2);
    	       }
       if(b1>10&&b2<10){
    	      //System.out.print(0);
    	       System.out.print(b1);
    	       System.out.print(":");
    	       System.out.print(0);
    	       System.out.print(b2);
    	       }

	}
		if(n==24)
		{
			String s = in.next();
			String a[]=s.split(":");

			int b1=Integer.valueOf(a[0]);
			int b2=Integer.valueOf(a[1]);

	       if(b1>23)
	       {
	    	   b1  = b1 % 10;
	       }

	       if(b2>59)
	       {
	    	   b2 = b2%10;
	       }

	       if(b1<10&&b2<10){
	    	      System.out.print(0);
	    	       System.out.print(b1);
	    	       System.out.print(":");
	    	       System.out.print(0);
	    	       System.out.print(b2);
	    	       }
	    	       if(b1>10&&b2>10){
	    	    	      //System.out.print(0);
	    	    	       System.out.print(b1);
	    	    	       System.out.print(":");
	    	    	       //System.out.print(0);
	    	    	       System.out.print(b2);
	    	    	       }
	    	       if(b1<10&&b2>10){
	    	    	      System.out.print(0);
	    	    	       System.out.print(b1);
	    	    	       System.out.print(":");
	    	    	       //System.out.print(0);
	    	    	       System.out.print(b2);
	    	    	       }
	    	       if(b1>10&&b2<10){
	    	    	      //System.out.print(0);
	    	    	       System.out.print(b1);
	    	    	       System.out.print(":");
	    	    	       System.out.print(0);
	    	    	       System.out.print(b2);
	    	    	       }

		}
	}
}


import java.util.Scanner;

public class a {

	public static void main(String[] args) {
		Scanner in=new Scanner(System.in);
		int n=in.nextInt();
		if(n==12)
		{
		String s = in.next();
		String a[]=s.split(":");

		int b1=Integer.valueOf(a[0]);
		int b2=Integer.valueOf(a[1]);

       if(b1>12)
       {
    	   b1  = b1 - 10;
       }
       if(b1==0)b1 = 1;

       if(b2>59)
       {
    	   b2 = b2%10;
       }
       if(b1<10&&b2<10){
      System.out.print(0);
       System.out.print(b1);
       System.out.print(":");
       System.out.print(0);
       System.out.print(b2);
       }
       if(b1>10&&b2>10){
    	      //System.out.print(0);
    	       System.out.print(b1);
    	       System.out.print(":");
    	       //System.out.print(0);
    	       System.out.print(b2);
    	       }
       if(b1<10&&b2>10){
    	      System.out.print(0);
    	       System.out.print(b1);
    	       System.out.print(":");
    	       //System.out.print(0);
    	       System.out.print(b2);
    	       }
       if(b1>10&&b2<10){
    	      //System.out.print(0);
    	       System.out.print(b1);
    	       System.out.print(":");
    	       System.out.print(0);
    	       System.out.print(b2);
    	       }

	}
		if(n==24)
		{
			String s = in.next();
			String a[]=s.split(":");

			int b1=Integer.valueOf(a[0]);
			int b2=Integer.valueOf(a[1]);

	       if(b1>23)
	       {
	    	   b1  = b1 % 10;
	       }

	       if(b2>59)
	       {
	    	   b2 = b2%10;
	       }

	       if(b1<10&&b2<10){
	    	      System.out.print(0);
	    	       System.out.print(b1);
	    	       System.out.print(":");
	    	       System.out.print(0);
	    	       System.out.print(b2);
	    	       }
	    	       if(b1>10&&b2>10){
	    	    	      //System.out.print(0);
	    	    	       System.out.print(b1);
	    	    	       System.out.print(":");
	    	    	       //System.out.print(0);
	    	    	       System.out.print(b2);
	    	    	       }
	    	       if(b1<10&&b2>10){
	    	    	      System.out.print(0);
	    	    	       System.out.print(b1);
	    	    	       System.out.print(":");
	    	    	       //System.out.print(0);
	    	    	       System.out.print(b2);
	    	    	       }
	    	       if(b1>10&&b2<10){
	    	    	      //System.out.print(0);
	    	    	       System.out.print(b1);
	    	    	       System.out.print(":");
	    	    	       System.out.print(0);
	    	    	       System.out.print(b2);
	    	    	       }

		}
	}
}


import java.util.Scanner;

public class a {

	public static void main(String[] args) {
		Scanner in=new Scanner(System.in);
		int n=in.nextInt();
		if(n==12)
		{
		String s = in.next();
		String a[]=s.split(":");

		int b1=Integer.valueOf(a[0]);
		int b2=Integer.valueOf(a[1]);

       if(b1>12)
       {
    	   b1  = b1 % 10;
       }
       if(b1==0)b1 = 1;

       if(b2>59)
       {
    	   b2 = b2%10;
       }
       if(b1<10&&b2<10){
      System.out.print(0);
       System.out.print(b1);
       System.out.print(":");
       System.out.print(0);
       System.out.print(b2);
       }
       if(b1>10&&b2>10){
    	      //System.out.print(0);
    	       System.out.print(b1);
    	       System.out.print(":");
    	       //System.out.print(0);
    	       System.out.print(b2);
    	       }
       if(b1<10&&b2>10){
    	      System.out.print(0);
    	       System.out.print(b1);
    	       System.out.print(":");
    	       //System.out.print(0);
    	       System.out.print(b2);
    	       }
       if(b1>10&&b2<10){
    	      //System.out.print(0);
    	       System.out.print(b1);
    	       System.out.print(":");
    	       System.out.print(0);
    	       System.out.print(b2);
    	       }

	}
		if(n==24)
		{
			String s = in.next();
			String a[]=s.split(":");

			int b1=Integer.valueOf(a[0]);
			int b2=Integer.valueOf(a[1]);

	       if(b1>23)
	       {
	    	   b1  = b1 % 10;
	       }

	       if(b2>59)
	       {
	    	   b2 = b2%10;
	       }

	       if(b1<10&&b2<10){
	    	      System.out.print(0);
	    	       System.out.print(b1);
	    	       System.out.print(":");
	    	       System.out.print(0);
	    	       System.out.print(b2);
	    	       }
	    	       if(b1>10&&b2>10){
	    	    	      //System.out.print(0);
	    	    	       System.out.print(b1);
	    	    	       System.out.print(":");
	    	    	       //System.out.print(0);
	    	    	       System.out.print(b2);
	    	    	       }
	    	       if(b1<10&&b2>10){
	    	    	      System.out.print(0);
	    	    	       System.out.print(b1);
	    	    	       System.out.print(":");
	    	    	       //System.out.print(0);
	    	    	       System.out.print(b2);
	    	    	       }
	    	       if(b1>10&&b2<10){
	    	    	      //System.out.print(0);
	    	    	       System.out.print(b1);
	    	    	       System.out.print(":");
	    	    	       System.out.print(0);
	    	    	       System.out.print(b2);
	    	    	       }

		}
	}
}


import java.util.Scanner;

public class a {

	public static void main(String[] args) {
	Scanner i = new Scanner(System.in);
	int f = i.nextInt();
	if(f==12)
	{
	Scanner in = new Scanner(System.in);
	String Str1 = in.nextLine();

    char[] Str2 = new char[100];
    char[] Str3 = new char[100];
    char[] Str4 = new char[100];
    char[] Str5 = new char[100];

       Str1.getChars(0, 2, Str2, 0);
       //System.out.println(Str2 );
       Str1.getChars(3, 5, Str3, 0);
       //System.out.println(Str3 );

       if(Str2[0]=='0')
       {
    	   Str4 = Str2;
       }
       else if(Str2[0]!='0')
       {
    	   Str4[0] = '0';
           Str4[1] = Str2[1];
       }
       int number = Integer.parseInt(String.valueOf(Str3[0]));
       int number1 = Integer.parseInt(String.valueOf(Str3[1]));
       int nu = number*10+number1;

       if(nu>59)
       {
    	   Str5[0] = '0';
    	   Str5[1] = Str3[1];
       }
       else
       {
    	   Str5= Str3;
       }
       System.out.print(Str4[0]);
       System.out.print(Str4[1]);
       System.out.print(":");
       System.out.print(Str5[0]);
       System.out.print(Str5[1]);

	}
	else if(f==24)
	{
		Scanner inp = new Scanner(System.in);
		String Str1 = inp.nextLine();

	    char[] S2 = new char[100];
	    char[] S3 = new char[100];
	    char[] S4 = new char[100];
	    char[] S5 = new char[100];

	       Str1.getChars(0, 2, S2, 0);
	       //System.out.println(Str2 );
	       Str1.getChars(3, 5, S3, 0);
	       //System.out.println(Str3 );

	       if(S2[0]=='0'||S2[0]=='1')
	       {
	    	   S4 = S2;
	       }
	       else if(S2[0]=='2')
	       {
	    	   S4[0] = S2[0];
	    	   int n1 = Integer.parseInt(String.valueOf(S2[1]));
	    	   if(n1>3){
	    		   S4[1]='0';
	    	   }
	    	   else
	    		   S4[1]=S2[1];

	       }
	       else if(S2[0]!='0'&&S2[0]!='1'&&S2[0]!='2')
	       {
	    	   S4[0] = '0';
	    	   S4[1] = S2[1];
	       }
	       int n3 = Integer.parseInt(String.valueOf(S3[0]));
	       int n4 = Integer.parseInt(String.valueOf(S3[1]));
	       int n5 = n3*10+n4;
	       if(n5>59)
	       {
	    	   S5[0] = '0';
	    	   S5[1] = S3[1];
	       }
	       else
	       {
	    	   S5= S3;
	       }
	       System.out.print(S4[0]);
	       System.out.print(S4[1]);
	       System.out.print(":");
	       System.out.print(S5[0]);
	       System.out.print(S5[1]);

		}
	}
}


import java.util.Scanner;

public class a {

	public static void main(String[] args) {
		Scanner in=new Scanner(System.in);
		int n=in.nextInt();
		if(n==12)
		{
		String s = in.next();
		String a[]=s.split(":");

		int b1=Integer.valueOf(a[0]);
		int b2=Integer.valueOf(a[1]);

       if(b1>12)
       {
    	   b1  = b1 % 10;
       }
       if(b1==0)b1 = b1+10;

       if(b2>59)
       {
    	   b2 = b2%10;
       }
       if(b1<10&&b2<10){
      System.out.print(0);
       System.out.print(b1);
       System.out.print(":");
       System.out.print(0);
       System.out.print(b2);
       }
       if(b1>=10&&b2>=10){
    	      //System.out.print(0);
    	       System.out.print(b1);
    	       System.out.print(":");
    	       //System.out.print(0);
    	       System.out.print(b2);
    	       }
       if(b1<10&&b2>=10){
    	      System.out.print(0);
    	       System.out.print(b1);
    	       System.out.print(":");
    	       //System.out.print(0);
    	       System.out.print(b2);
    	       }
       if(b1>=10&&b2<10){
    	      //System.out.print(0);
    	       System.out.print(b1);
    	       System.out.print(":");
    	       System.out.print(0);
    	       System.out.print(b2);
    	       }

	}
		if(n==24)
		{
			String s = in.next();
			String a[]=s.split(":");

			int b1=Integer.valueOf(a[0]);
			int b2=Integer.valueOf(a[1]);

	       if(b1>23)
	       {
	    	   b1  = b1 % 10;
	       }

	       if(b2>59)
	       {
	    	   b2 = b2%10;
	       }

	       if(b1<10&&b2<10){
	    	      System.out.print(0);
	    	       System.out.print(b1);
	    	       System.out.print(":");
	    	       System.out.print(0);
	    	       System.out.print(b2);
	    	       }
	    	       if(b1>=10&&b2>=10){
	    	    	      //System.out.print(0);
	    	    	       System.out.print(b1);
	    	    	       System.out.print(":");
	    	    	       //System.out.print(0);
	    	    	       System.out.print(b2);
	    	    	       }
	    	       if(b1<10&&b2>=10){
	    	    	      System.out.print(0);
	    	    	       System.out.print(b1);
	    	    	       System.out.print(":");
	    	    	       //System.out.print(0);
	    	    	       System.out.print(b2);
	    	    	       }
	    	       if(b1>=10&&b2<10){
	    	    	      //System.out.print(0);
	    	    	       System.out.print(b1);
	    	    	       System.out.print(":");
	    	    	       System.out.print(0);
	    	    	       System.out.print(b2);
	    	    	       }

		}
	}
}


import java.util.Scanner;

public class a {

	public static void main(String[] args) {
	Scanner i = new Scanner(System.in);
	int f = i.nextInt();
	if(f==12)
	{
	Scanner in = new Scanner(System.in);
	String Str1 = in.nextLine();

    char[] Str2 = new char[100];
    char[] Str3 = new char[100];
    char[] Str4 = new char[100];
    char[] Str5 = new char[100];

       Str1.getChars(0, 2, Str2, 0);
       //System.out.println(Str2 );
       Str1.getChars(3, 5, Str3, 0);
       //System.out.println(Str3 );

       if(Str2[0]=='0')
       {
    	   Str4 = Str2;
       }
       else if(Str2[0]!='0')
       {
    	   Str4[0] = '0';
           Str4[1] = Str2[1];
       }
       int number = Integer.parseInt(String.valueOf(Str3[0]));
       int number1 = Integer.parseInt(String.valueOf(Str3[1]));
       int nu = number*10+number1;

       if(nu>59)
       {
    	   Str5[0] = '0';
    	   Str5[1] = Str3[1];
       }
       else
       {
    	   Str5= Str3;
       }
       System.out.print(Str4[0]);
       System.out.print(Str4[1]);
       System.out.print(":");
       System.out.print(Str5[0]);
       System.out.print(Str5[1]);

	}
	else if(f==24)
	{
		Scanner inp = new Scanner(System.in);
		String Str1 = inp.nextLine();

	    char[] Str2 = new char[100];
	    char[] Str3 = new char[100];
	    char[] Str4 = new char[100];
	    char[] Str5 = new char[100];

	       Str1.getChars(0, 2, Str2, 0);
	       //System.out.println(Str2 );
	       Str1.getChars(3, 5, Str3, 0);
	       //System.out.println(Str3 );

	       if(Str2[0]=='0'||Str2[0]=='1')
	       {
	    	   Str4 = Str2;
	       }
	       else if(Str2[0]=='2')
	       {
	    	   Str4[0] = Str2[0];
	    	   int n1 = Integer.parseInt(String.valueOf(Str2[1]));
	    	   if(n1>3){
	    		   Str4[1]='0';
	    	   }
	    	   else
	    		   Str4[1]=Str2[1];

	       }
	       else if(Str2[0]!='0'&&Str2[0]!='1'&&Str2[0]!='2')
	       {
	    	   Str4[0] = '0';
	    	   Str4[1] = Str2[1];
	       }
	       int n3 = Integer.parseInt(String.valueOf(Str3[0]));
	       int n4 = Integer.parseInt(String.valueOf(Str3[1]));
	       int n5 = n3*10+n4;
	       if(n5>59)
	       {
	    	   Str5[0] = '0';
	    	   Str5[1] = Str3[1];
	       }
	       else
	       {
	    	   Str5= Str3;
	       }
	       System.out.print(Str4[0]);
	       System.out.print(Str4[1]);
	       System.out.print(":");
	       System.out.print(Str5[0]);
	       System.out.print(Str5[1]);

		}

	}

	}


import java.util.Scanner;

public class a {

	public static void main(String[] args) {
		Scanner in=new Scanner(System.in);
		int n=in.nextInt();
		if(n==12)
		{
		String s = in.next();
		String a[]=s.split(":");

		int b1=Integer.valueOf(a[0]);
		int b2=Integer.valueOf(a[1]);

       if(b1>12)
       {
    	   b1  = b1 % 10;
       }
       if(b1==0)b1 = b1+10;

       if(b2>59)
       {
    	   b2 = b2%10;
       }
       if(b1<10&&b2<10){
      System.out.print(0);
       System.out.print(b1);
       System.out.print(":");
       System.out.print(0);
       System.out.print(b2);
       }
       if(b1>=10&&b2>=10){
    	      //System.out.print(0);
    	       System.out.print(b1);
    	       System.out.print(":");
    	       //System.out.print(0);
    	       System.out.print(b2);
    	       }
       if(b1<10&&b2>=10){
    	      System.out.print(0);
    	       System.out.print(b1);
    	       System.out.print(":");
    	       //System.out.print(0);
    	       System.out.print(b2);
    	       }
       if(b1>=10&&b2<10){
    	      //System.out.print(0);
    	       System.out.print(b1);
    	       System.out.print(":");
    	       System.out.print(0);
    	       System.out.print(b2);
    	       }

	}
		if(n==24)
		{
			String s = in.next();
			String a[]=s.split(":");

			int b1=Integer.valueOf(a[0]);
			int b2=Integer.valueOf(a[1]);

	       if(b1>23)
	       {
	    	   b1  = b1 % 10;
	       }
	       if(b1==0)b1 = b1+10;

	       if(b2>59)
	       {
	    	   b2 = b2%10;
	       }

	       if(b1<10&&b2<10){
	    	      System.out.print(0);
	    	       System.out.print(b1);
	    	       System.out.print(":");
	    	       System.out.print(0);
	    	       System.out.print(b2);
	    	       }
	    	       if(b1>=10&&b2>=10){
	    	    	      //System.out.print(0);
	    	    	       System.out.print(b1);
	    	    	       System.out.print(":");
	    	    	       //System.out.print(0);
	    	    	       System.out.print(b2);
	    	    	       }
	    	       if(b1<10&&b2>=10){
	    	    	      System.out.print(0);
	    	    	       System.out.print(b1);
	    	    	       System.out.print(":");
	    	    	       //System.out.print(0);
	    	    	       System.out.print(b2);
	    	    	       }
	    	       if(b1>=10&&b2<10){
	    	    	      //System.out.print(0);
	    	    	       System.out.print(b1);
	    	    	       System.out.print(":");
	    	    	       System.out.print(0);
	    	    	       System.out.print(b2);
	    	    	       }

		}
	}
}


import java.util.Scanner;

public class a {

	public static void main(String[] args) {
	Scanner i = new Scanner(System.in);
	int f = i.nextInt();
	if(f==12)
	{
	Scanner in = new Scanner(System.in);
	String Str1 = in.nextLine();

    char[] Str2 = new char[2];
    char[] Str3 = new char[2];
    char[] Str4 = new char[2];
    char[] Str5 = new char[2];

       Str1.getChars(0, 2, Str2, 0);
       //System.out.println(Str2 );
       Str1.getChars(3, 5, Str3, 0);
       //System.out.println(Str3 );

       if(Str2[0]=='0')
       {
    	   Str4 = Str2;
       }
       else if(Str2[0]!='0')
       {
    	   Str4[0] = '0';
           Str4[1] = Str2[1];
       }
       int number = Integer.parseInt(String.valueOf(Str3));
       if(number>59)
       {
    	   Str5[0] = '0';
    	   Str5[1] = Str3[1];
       }
       else
       {
    	   Str5= Str3;
       }
       System.out.print(Str4);
       System.out.print(":");
       System.out.print(Str5);

	}
	else if(f==24)
	{
		Scanner inp = new Scanner(System.in);
		String Str1 = inp.nextLine();

	    char[] Str2 = new char[2];
	    char[] Str3 = new char[2];
	    char[] Str4 = new char[2];
	    char[] Str5 = new char[2];

	       Str1.getChars(0, 2, Str2, 0);
	       //System.out.println(Str2 );
	       Str1.getChars(3, 5, Str3, 0);
	       //System.out.println(Str3 );

	       if(Str2[0]=='0'||Str2[0]=='1')
	       {
	    	   Str4 = Str2;
	       }
	       else if(Str2[0]=='2')
	       {
	    	   Str4[0] = Str2[0];
	    	   int n1 = Integer.parseInt(String.valueOf(Str2[1]));
	    	   if(n1>3){
	    		   Str4[1]='0';
	    	   }
	    	   else
	    		   Str4[1]=Str2[1];

	       }
	       else if(Str2[0]!='0'&&Str2[0]!='1'&&Str2[0]!='2')
	       {
	    	   Str4[0] = '0';
	    	   Str4[1] = Str2[1];
	       }
	       int n3 = Integer.parseInt(String.valueOf(Str3));
	       if(n3>59)
	       {
	    	   Str5[0] = '0';
	    	   Str5[1] = Str3[1];
	       }
	       else
	       {
	    	   Str5= Str3;
	       }
	       System.out.print(Str4);
	       System.out.print(":");
	       System.out.print(Str5);

		}

	}

	}


import java.text.DecimalFormat;
import java.util.Scanner;

public class A {

	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		DecimalFormat f = new DecimalFormat("00");
		int n = scan.nextInt();
		String[] split = scan.next().split("[:]");
		int h = Integer.parseInt(split[0]), m = Integer.parseInt(split[1]);
		while(h > n) h %= 10;
		while(m >= 60) m%=10;
		if(n == 12 && h == 0)h++;
		System.out.println(f.format(h)+":"+f.format(m));
	}

}


import java.text.DecimalFormat;
import java.util.Scanner;

public class A {

	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		DecimalFormat f = new DecimalFormat("00");
		int n = scan.nextInt();
		String[] split = scan.next().split("[:]");
		int h = Integer.parseInt(split[0]), m = Integer.parseInt(split[1]);
		while(h >= n) h%=10;
		while(m >= 60) m%=10;
		if(n == 12 && h == 0)h++;
		System.out.println(f.format(h)+":"+f.format(m));
	}

}


import java.text.DecimalFormat;
import java.util.Scanner;

public class A {

	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		DecimalFormat f = new DecimalFormat("00");
		int n = scan.nextInt();
		String[] split = scan.next().split("[:]");
		int h = Integer.parseInt(split[0]), m = Integer.parseInt(split[1]);
		while(h > n) h %= 10;
		while(m >= 60) m%=10;
		System.out.println(f.format(h)+":"+f.format(m));
	}

}


import java.text.DecimalFormat;
import java.util.Scanner;

public class A {

	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		DecimalFormat f = new DecimalFormat("00");
		int n = scan.nextInt();
		String[] split = scan.next().split("[:]");
		int h = Integer.parseInt(split[0]), m = Integer.parseInt(split[1]);
		if(n==12)while(h > 12) h%=10;
		if(n==24)while(h >= 24) h%=10;
		while(m >= 60) m%=10;
		if(n == 12 && h == 0)h++;
		System.out.println(f.format(h)+":"+f.format(m));
	}

}


import java.text.DecimalFormat;
import java.util.Scanner;

public class A {

	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		DecimalFormat f = new DecimalFormat("00");
		int n = scan.nextInt();
		String[] split = scan.next().split("[:]");
		int h = Integer.parseInt(split[0]), m = Integer.parseInt(split[1]);
		while(h >= n) h %= 10;
		while(m >= 60) m%=10;
		System.out.println(f.format(h)+":"+f.format(m));
	}

}


import java.text.DecimalFormat;
import java.util.Scanner;

public class A {

	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		DecimalFormat f = new DecimalFormat("00");
		int n = scan.nextInt();
		String[] split = scan.next().split("[:]");
		int h = Integer.parseInt(split[0]), m = Integer.parseInt(split[1]);
		if(n==12)while(h > 12) h-=10;
		if(n==24)while(h >= 24) h-=10;
		while(m >= 60) m-=10;
		if(n == 12 && h == 0)h++;
		System.out.println(f.format(h)+":"+f.format(m));
	}

}


import java.text.DecimalFormat;
import java.util.Scanner;

public class A {

	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		DecimalFormat f = new DecimalFormat("00");
		int n = scan.nextInt();
		String[] split = scan.next().split("[:]");
		int h = Integer.parseInt(split[0]), m = Integer.parseInt(split[1]);
		while(h > n) h %= 10;
		while(m > 60) m%=10;
		System.out.println(f.format(h)+":"+f.format(m));
	}

}


import java.util.*;
import java.math.*;
public class clockA {
	public static void main(String args[]) {
		Scanner in = new Scanner(System.in);
		int format = in.nextInt();
		in.nextLine();
		String time = in.nextLine();
		int hour1 = Integer.parseInt(time.substring(0, 1));
		int hour2 = Integer.parseInt(time.substring(1, time.indexOf(":")));
		int minute1 = Integer.parseInt(time.substring(time.indexOf(":") + 1, time.indexOf(":") + 2));
		int minute2 = Integer.parseInt(time.substring(time.indexOf(":") + 2));
		int hour = hour1*10 + hour2;
		int minute = minute1*10 + minute2;
		if(format == 12) {
			if(hour <= 12 && minute < 60 && hour > 0) { //correct format
				System.out.println(hour1 + "" + hour2 + ":" + minute1 + "" + minute2);
			} else {
				if(hour1 == 0 && hour2 == 0) {
					hour2 = 3;
				}

				if(hour > 12) {
					hour1 = 0;
				}

				if(minute >= 60) {
					minute1 = 4;
				}

				System.out.println(hour1 + "" + hour2 + ":" + minute1 + "" + minute2);
			}

		} else if(format == 24) {
			if(hour < 24 && minute < 60) { //correct format
				System.out.println(hour1 + "" + hour2 + ":" + minute1 + "" + minute2);
			} else {
				if(hour >= 24) {
					hour1 = 0;
				}

				if(minute >= 60) {
					minute1 = 4;
				}

				System.out.println(hour1 + "" + hour2 + ":" + minute1 + "" + minute2);
			}

		}
	}
}


import java.util.*;
import java.math.*;
public class clockA {
	public static void main(String args[]) {
		Scanner in = new Scanner(System.in);
		int format = in.nextInt();
		in.nextLine();
		String time = in.nextLine();
		int hour1 = Integer.parseInt(time.substring(0, 1));
		int hour2 = Integer.parseInt(time.substring(1, time.indexOf(":")));
		int minute1 = Integer.parseInt(time.substring(time.indexOf(":") + 1, time.indexOf(":") + 2));
		int minute2 = Integer.parseInt(time.substring(time.indexOf(":") + 2));
		int hour = hour1*10 + hour2;
		int minute = minute1*10 + minute2;
		if(format == 12) {
			if(hour <= 12 && minute < 60 && hour > 0) { //correct format
				System.out.println(hour1 + "" + hour2 + ":" + minute1 + "" + minute2);
			} else {
				if(hour1 == 0 && hour2 == 0) {
					hour2 = 3;
				}

				if(hour > 12) {
					hour1 = 1;
				}

				if(minute >= 60) {
					minute1 = 4;
				}

				System.out.println(hour1 + "" + hour2 + ":" + minute1 + "" + minute2);
			}

		} else if(format == 24) {
			if(hour < 24 && minute < 60) { //correct format
				System.out.println(hour1 + "" + hour2 + ":" + minute1 + "" + minute2);
			} else {
				if(hour >= 24) {
					hour1 = 0;
				}

				if(minute >= 60) {
					minute1 = 4;
				}

				System.out.println(hour1 + "" + hour2 + ":" + minute1 + "" + minute2);
			}

		}
	}
}


import java.util.*;
import java.math.*;
public class clockA {
	public static void main(String args[]) {
		Scanner in = new Scanner(System.in);
		int format = in.nextInt();
		in.nextLine();
		String time = in.nextLine();
		int hour1 = Integer.parseInt(time.substring(0, 1));
		int hour2 = Integer.parseInt(time.substring(1, time.indexOf(":")));
		int minute1 = Integer.parseInt(time.substring(time.indexOf(":") + 1, time.indexOf(":") + 2));
		int minute2 = Integer.parseInt(time.substring(time.indexOf(":") + 2));
		int hour = hour1*10 + hour2;
		int minute = minute1*10 + minute2;
		if(format == 12) {
			if(hour <= 12 && minute < 60 && hour > 0) { //correct format
				System.out.println(hour1 + "" + hour2 + ":" + minute1 + "" + minute2);
			} else {
				if(hour1 == 0 && hour2 == 0) {
					hour2 = 3;
				}

				if(hour > 12) {
					hour1 = 0;
				}

				if(hour > 12 && hour2 == 0) {
					hour1 = 1
				}

				if(minute >= 60) {
					minute1 = 4;
				}

				System.out.println(hour1 + "" + hour2 + ":" + minute1 + "" + minute2);
			}

		} else if(format == 24) {
			if(hour < 24 && minute < 60) { //correct format
				System.out.println(hour1 + "" + hour2 + ":" + minute1 + "" + minute2);
			} else {
				if(hour >= 24) {
					hour1 = 0;
				}

				if(minute >= 60) {
					minute1 = 4;
				}

				System.out.println(hour1 + "" + hour2 + ":" + minute1 + "" + minute2);
			}

		}
	}
}


import java.util.*;
import java.math.*;
public class clockA {
	public static void main(String args[]) {
		Scanner in = new Scanner(System.in);
		int format = in.nextInt();
		in.nextLine();
		String time = in.nextLine();
		int hour1 = Integer.parseInt(time.substring(0, 1));
		int hour2 = Integer.parseInt(time.substring(1, time.indexOf(":")));
		int minute1 = Integer.parseInt(time.substring(time.indexOf(":") + 1, time.indexOf(":") + 2));
		int minute2 = Integer.parseInt(time.substring(time.indexOf(":") + 2));
		int hour = hour1*10 + hour2;
		int minute = minute1*10 + minute2;
		if(format == 12) {
			if(hour <= 12 && minute < 60 && hour > 0) { //correct format
				System.out.println(hour1 + "" + hour2 + ":" + minute1 + "" + minute2);
			} else {
				if(hour1 == 0 && hour2 == 0) {
					hour2 = 2;
				}

				if(hour > 12) {
					hour1 = 0;
				}

				if(minute >= 60) {
					minute1 = 0;
				}

				System.out.println(hour1 + "" + hour2 + ":" + minute1 + "" + minute2);
			}

		} else if(format == 24) {
			if(hour < 24 && minute < 60) { //correct format
				System.out.println(hour1 + "" + hour2 + ":" + minute1 + "" + minute2);
			} else {
				if(hour >= 24) {
					hour1 = 0;
				}

				if(minute >= 60) {
					minute1 = 0;
				}

				System.out.println(hour1 + "" + hour2 + ":" + minute1 + "" + minute2);
			}

		}
	}
}


import java.util.*;
import java.math.*;
public class clockA {
	public static void main(String args[]) {
		Scanner in = new Scanner(System.in);
		int format = in.nextInt();
		in.nextLine();
		String time = in.nextLine();
		int hour1 = Integer.parseInt(time.substring(0, 1));
		int hour2 = Integer.parseInt(time.substring(1, time.indexOf(":")));
		int minute1 = Integer.parseInt(time.substring(time.indexOf(":") + 1, time.indexOf(":") + 2));
		int minute2 = Integer.parseInt(time.substring(time.indexOf(":") + 2));
		int hour = hour1*10 + hour2;
		int minute = minute1*10 + minute2;
		if(format == 12) {
			if(hour <= 12 && minute < 60 && hour > 0) { //correct format
				System.out.println(hour + ":" + minute);
			} else {
				if(hour1 == 0 && hour2 == 0) {
					hour2 = 1;
				}

				if(hour > 12) {
					hour1 = 0;
				}

				if(minute >= 60) {
					minute1 = 0;
				}

				System.out.println(hour1 + "" + hour2 + ":" + minute1 + "" + minute2);
			}

		} else if(format == 24) {
			if(hour < 24 && minute < 60) { //correct format
				System.out.println(hour + ":" + minute);
			} else {
				if(hour >= 24) {
					hour1 = 0;
				}

				if(minute >= 60) {
					minute1 = 0;
				}

				System.out.println(hour1 + "" + hour2 + ":" + minute1 + "" + minute2);
			}

		}
	}
}


import java.util.*;
import java.math.*;
public class clockA {
	public static void main(String args[]) {
		Scanner in = new Scanner(System.in);
		int format = in.nextInt();
		in.nextLine();
		String time = in.nextLine();
		int hour1 = Integer.parseInt(time.substring(0, 1));
		int hour2 = Integer.parseInt(time.substring(1, time.indexOf(":")));
		int minute1 = Integer.parseInt(time.substring(time.indexOf(":") + 1, time.indexOf(":") + 2));
		int minute2 = Integer.parseInt(time.substring(time.indexOf(":") + 2));
		int hour = hour1*10 + hour2;
		int minute = minute1*10 + minute2;
		if(format == 12) {
			if(hour <= 12 && minute < 60 && hour > 0) { //correct format
				System.out.println(hour1 + "" + hour2 + ":" + minute1 + "" + minute2);
			} else {
				if(hour1 == 0 && hour2 == 0) {
					hour2 = 3;
				}

				if(hour > 12) {
					hour1 = 0;
				}

				if(hour > 12 && hour2 == 0) {
					hour1 = 1;
				}

				if(minute >= 60) {
					minute1 = 4;
				}

				System.out.println(hour1 + "" + hour2 + ":" + minute1 + "" + minute2);
			}

		} else if(format == 24) {
			if(hour < 24 && minute < 60) { //correct format
				System.out.println(hour1 + "" + hour2 + ":" + minute1 + "" + minute2);
			} else {
				if(hour >= 24) {
					hour1 = 0;
				}

				if(minute >= 60) {
					minute1 = 4;
				}

				System.out.println(hour1 + "" + hour2 + ":" + minute1 + "" + minute2);
			}

		}
	}
}


import java.util.*;
import java.math.*;
public class clockA {
	public static void main(String args[]) {
		Scanner in = new Scanner(System.in);
		int format = in.nextInt();
		in.nextLine();
		String time = in.nextLine();
		int hour1 = Integer.parseInt(time.substring(0, 1));
		int hour2 = Integer.parseInt(time.substring(1, time.indexOf(":")));
		int minute1 = Integer.parseInt(time.substring(time.indexOf(":") + 1, time.indexOf(":") + 2));
		int minute2 = Integer.parseInt(time.substring(time.indexOf(":") + 2));
		int hour = hour1*10 + hour2;
		int minute = minute1*10 + minute2;
		if(format == 12) {
			if(hour <= 12 && minute < 60 && hour > 0) { //correct format
				System.out.println(hour1 + "" + hour2 + ":" + minute1 + "" + minute2);
			} else {
				if(hour1 == 0 && hour2 == 0) {
					hour2 = 3;
				}

				if(hour > 12) {
					hour1 = 0;
				}

				if(minute >= 60) {
					minute1 = 3;
				}

				System.out.println(hour1 + "" + hour2 + ":" + minute1 + "" + minute2);
			}

		} else if(format == 24) {
			if(hour < 24 && minute < 60) { //correct format
				System.out.println(hour1 + "" + hour2 + ":" + minute1 + "" + minute2);
			} else {
				if(hour >= 24) {
					hour1 = 0;
				}

				if(minute >= 60) {
					minute1 = 3;
				}

				System.out.println(hour1 + "" + hour2 + ":" + minute1 + "" + minute2);
			}

		}
	}
}


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.StringTokenizer;

public class A {

	public static void main(String[] args) throws IOException {
		Scanner sc = new Scanner(System.in);
		PrintWriter out = new PrintWriter(System.out);
		int n = sc.nextInt();
		String s = sc.next();

		int pre = Integer.parseInt(s.substring(0, 2));
		int post = Integer.parseInt(s.substring(3));
		StringBuilder sb = new StringBuilder();
		if (n == 12) {
			if (pre == 0) {
				sb.append("01");
			} else if (pre > 12 && pre / 10 > 1) {
				sb.append("0" + (((pre%10)==0)? 1:(pre%10)));
			} else if (pre > 12 && pre / 10 == 1) {
				sb.append("10");
			} else
				sb.append(pre);

			sb.append(":");
			if (post >= 60) {
				sb.append("0" + post % 10);
			} else
				sb.append((post==0? "00":post));
		} else {
			if (pre >= 24) {
				sb.append("0" + pre % 10);
			} else
				sb.append(pre);

			sb.append(":");
			if (post >= 60) {
				sb.append("0" + post % 10);
			} else
				sb.append((post)==0? "00":post);
		}

		out.println(sb.toString());

		out.flush();
		out.close();
	}

	static class Scanner {
		StringTokenizer st;
		BufferedReader br;

		public Scanner(InputStream s) {
			br = new BufferedReader(new InputStreamReader(s));
		}

		public String next() throws IOException {
			while (st == null || !st.hasMoreTokens())
				st = new StringTokenizer(br.readLine());
			return st.nextToken();
		}

		public int nextInt() throws IOException {
			return Integer.parseInt(next());
		}

		public long nextLong() throws IOException {
			return Long.parseLong(next());
		}

		public String nextLine() throws IOException {
			return br.readLine();
		}

		public double nextDouble() throws IOException {
			String x = next();
			StringBuilder sb = new StringBuilder("0");
			double res = 0, f = 1;
			boolean dec = false, neg = false;
			int start = 0;
			if (x.charAt(0) == '-') {
				neg = true;
				start++;
			}
			for (int i = start; i < x.length(); i++)
				if (x.charAt(i) == '.') {
					res = Long.parseLong(sb.toString());
					sb = new StringBuilder("0");
					dec = true;
				} else {
					sb.append(x.charAt(i));
					if (dec)
						f *= 10;
				}
			res += Long.parseLong(sb.toString()) / f;
			return res * (neg ? -1 : 1);
		}

		public boolean ready() throws IOException {
			return br.ready();
		}

	}
}


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.StringTokenizer;

public class A {

	public static void main(String[] args) throws IOException {
		Scanner sc= new Scanner(System.in);
		PrintWriter out= new PrintWriter(System.out);
		int n=sc.nextInt();
		String s= sc.next();

			int pre= Integer.parseInt(s.substring(0, 2));
			int post= Integer.parseInt(s.substring(3));
			StringBuilder sb= new StringBuilder();
			if(n==12){
				if (pre==0){
					sb.append("01");
				}
				else
				if(pre>12 && pre/10>1){
					sb.append("0"+pre%10);
				}
				else
					if(pre>12 && pre/10==1){
						sb.append("10");
					}
					else
						sb.append(pre);

				sb.append(":");
				if(post>=60){
					sb.append("0"+ post%10);
				}else
					sb.append(post);
			}
			else
			{
				if(pre>=24){
					sb.append("0"+pre%10);
				}
				else
					sb.append(pre);

				sb.append(":");
				if(post>=60){
					sb.append("0"+ post%10);
				}else
					sb.append(post);
			}

			out.println(sb.toString());

		out.flush();
		out.close();
	}

	static class Scanner
	{
		StringTokenizer st;
		BufferedReader br;

		public Scanner(InputStream s){	br = new BufferedReader(new InputStreamReader(s));}

		public String next() throws IOException
		{
			while (st == null || !st.hasMoreTokens())
				st = new StringTokenizer(br.readLine());
			return st.nextToken();
		}

		public int nextInt() throws IOException {return Integer.parseInt(next());}

		public long nextLong() throws IOException {return Long.parseLong(next());}

		public String nextLine() throws IOException {return br.readLine();}

		public double nextDouble() throws IOException
		{
			String x = next();
			StringBuilder sb = new StringBuilder("0");
			double res = 0, f = 1;
			boolean dec = false, neg = false;
			int start = 0;
			if(x.charAt(0) == '-')
			{
				neg = true;
				start++;
			}
			for(int i = start; i < x.length(); i++)
				if(x.charAt(i) == '.')
				{
					res = Long.parseLong(sb.toString());
					sb = new StringBuilder("0");
					dec = true;
				}
				else
				{
					sb.append(x.charAt(i));
					if(dec)
						f *= 10;
				}
			res += Long.parseLong(sb.toString()) / f;
			return res * (neg?-1:1);
		}

		public boolean ready() throws IOException {return br.ready();}

	}
}


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.StringTokenizer;

public class A {

	public static void main(String[] args) throws IOException {
		Scanner sc = new Scanner(System.in);
		PrintWriter out = new PrintWriter(System.out);
		int n = sc.nextInt();
		String s = sc.next();

		int pre = Integer.parseInt(s.substring(0, 2));
		int post = Integer.parseInt(s.substring(3));
		StringBuilder sb = new StringBuilder();
		if (n == 12) {
			if (pre == 0) {
				sb.append("01");
			} else if (pre > 12 && pre>=20) {

				sb.append("1" + (((pre%10)>2)? 1:(pre%10)));
			} else if (pre > 12 && pre <20) {
				sb.append("10");
			} else
				sb.append(pre<10? "0"+pre :pre);

			sb.append(":");
			if (post >= 60) {
				sb.append("0" + post % 10);
			} else
				sb.append((post<10? "0"+post:post));
		} else {
			if (pre >= 24) {
				sb.append("0" + pre % 10);
			} else
				sb.append(pre<10? "0"+pre:pre);

			sb.append(":");
			if (post >= 60) {
				sb.append("0" + post % 10);
			} else
				sb.append((post)<10? "0"+post:post);
		}

		out.println(sb.toString());

		out.flush();
		out.close();
	}

	static class Scanner {
		StringTokenizer st;
		BufferedReader br;

		public Scanner(InputStream s) {
			br = new BufferedReader(new InputStreamReader(s));
		}

		public String next() throws IOException {
			while (st == null || !st.hasMoreTokens())
				st = new StringTokenizer(br.readLine());
			return st.nextToken();
		}

		public int nextInt() throws IOException {
			return Integer.parseInt(next());
		}

		public long nextLong() throws IOException {
			return Long.parseLong(next());
		}

		public String nextLine() throws IOException {
			return br.readLine();
		}

		public double nextDouble() throws IOException {
			String x = next();
			StringBuilder sb = new StringBuilder("0");
			double res = 0, f = 1;
			boolean dec = false, neg = false;
			int start = 0;
			if (x.charAt(0) == '-') {
				neg = true;
				start++;
			}
			for (int i = start; i < x.length(); i++)
				if (x.charAt(i) == '.') {
					res = Long.parseLong(sb.toString());
					sb = new StringBuilder("0");
					dec = true;
				} else {
					sb.append(x.charAt(i));
					if (dec)
						f *= 10;
				}
			res += Long.parseLong(sb.toString()) / f;
			return res * (neg ? -1 : 1);
		}

		public boolean ready() throws IOException {
			return br.ready();
		}

	}
}


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.StringTokenizer;

public class A {

	public static void main(String[] args) throws IOException {
		Scanner sc = new Scanner(System.in);
		PrintWriter out = new PrintWriter(System.out);
		int n = sc.nextInt();
		String s = sc.next();

		int pre = Integer.parseInt(s.substring(0, 2));
		int post = Integer.parseInt(s.substring(3));
		StringBuilder sb = new StringBuilder();
		if (n == 12) {
			if (pre == 0) {
				sb.append("01");
			} else if (pre > 12 && pre / 10 > 1) {
				sb.append("0" + (((pre%10)==0)? 1:(pre%10)));
			} else if (pre > 12 && pre / 10 == 1) {
				sb.append("10");
			} else
				sb.append(pre);

			sb.append(":");
			if (post >= 60) {
				sb.append("0" + post % 10);
			} else
				sb.append(post);
		} else {
			if (pre >= 24) {
				sb.append("0" + pre % 10);
			} else
				sb.append(pre);

			sb.append(":");
			if (post >= 60) {
				sb.append("0" + post % 10);
			} else
				sb.append(post);
		}

		out.println(sb.toString());

		out.flush();
		out.close();
	}

	static class Scanner {
		StringTokenizer st;
		BufferedReader br;

		public Scanner(InputStream s) {
			br = new BufferedReader(new InputStreamReader(s));
		}

		public String next() throws IOException {
			while (st == null || !st.hasMoreTokens())
				st = new StringTokenizer(br.readLine());
			return st.nextToken();
		}

		public int nextInt() throws IOException {
			return Integer.parseInt(next());
		}

		public long nextLong() throws IOException {
			return Long.parseLong(next());
		}

		public String nextLine() throws IOException {
			return br.readLine();
		}

		public double nextDouble() throws IOException {
			String x = next();
			StringBuilder sb = new StringBuilder("0");
			double res = 0, f = 1;
			boolean dec = false, neg = false;
			int start = 0;
			if (x.charAt(0) == '-') {
				neg = true;
				start++;
			}
			for (int i = start; i < x.length(); i++)
				if (x.charAt(i) == '.') {
					res = Long.parseLong(sb.toString());
					sb = new StringBuilder("0");
					dec = true;
				} else {
					sb.append(x.charAt(i));
					if (dec)
						f *= 10;
				}
			res += Long.parseLong(sb.toString()) / f;
			return res * (neg ? -1 : 1);
		}

		public boolean ready() throws IOException {
			return br.ready();
		}

	}
}


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.StringTokenizer;

public class A {

	public static void main(String[] args) throws IOException {
		Scanner sc = new Scanner(System.in);
		PrintWriter out = new PrintWriter(System.out);
		int n = sc.nextInt();
		String s = sc.next();

		int pre = Integer.parseInt(s.substring(0, 2));
		int post = Integer.parseInt(s.substring(3));
		StringBuilder sb = new StringBuilder();
		if (n == 12) {
			if (pre == 0) {
				sb.append("01");
			} else if (pre > 12 && pre / 10 > 1) {
				sb.append("0" + (((pre%10)==0)? 1:(pre%10)));
			} else if (pre > 12 && pre / 10 == 1) {
				sb.append("10");
			} else
				sb.append(pre);

			sb.append(":");
			if (post >= 60) {
				sb.append("0" + post % 10);
			} else
				sb.append((post==0? "00":post));
		} else {
			if (pre >= 24) {
				sb.append("0" + pre % 10);
			} else
				sb.append(pre==0? "00":pre);

			sb.append(":");
			if (post >= 60) {
				sb.append("0" + post % 10);
			} else
				sb.append((post)==0? "00":post);
		}

		out.println(sb.toString());

		out.flush();
		out.close();
	}

	static class Scanner {
		StringTokenizer st;
		BufferedReader br;

		public Scanner(InputStream s) {
			br = new BufferedReader(new InputStreamReader(s));
		}

		public String next() throws IOException {
			while (st == null || !st.hasMoreTokens())
				st = new StringTokenizer(br.readLine());
			return st.nextToken();
		}

		public int nextInt() throws IOException {
			return Integer.parseInt(next());
		}

		public long nextLong() throws IOException {
			return Long.parseLong(next());
		}

		public String nextLine() throws IOException {
			return br.readLine();
		}

		public double nextDouble() throws IOException {
			String x = next();
			StringBuilder sb = new StringBuilder("0");
			double res = 0, f = 1;
			boolean dec = false, neg = false;
			int start = 0;
			if (x.charAt(0) == '-') {
				neg = true;
				start++;
			}
			for (int i = start; i < x.length(); i++)
				if (x.charAt(i) == '.') {
					res = Long.parseLong(sb.toString());
					sb = new StringBuilder("0");
					dec = true;
				} else {
					sb.append(x.charAt(i));
					if (dec)
						f *= 10;
				}
			res += Long.parseLong(sb.toString()) / f;
			return res * (neg ? -1 : 1);
		}

		public boolean ready() throws IOException {
			return br.ready();
		}

	}
}


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.StringTokenizer;

public class A {

	public static int dist(String s, String s2) {
		int c = 0;
		for (int i = 0; i < s.length(); i++) {
			if (s.charAt(i) != s2.charAt(i))
				c++;
		}
		return c;
	}

	public static void main(String[] args) throws IOException {
		Scanner sc = new Scanner(System.in);
		PrintWriter out = new PrintWriter(System.out);
		int n = sc.nextInt();
		String s = sc.next();
		int min = 4;
		String ans = "";
		if (n == 12) {
			for (int i = 0; i <= 1; i++) {
				if (i == 0)
					for (int j = 1; j <= 9; j++) {
						for (int k = 0; k < 6; k++) {
							for (int l = 0; l <= 9; l++) {
								int t = dist(s, i + "" + j + ":" + k + l);
								if (t < min) {
									min = t;
									ans = i + "" + j + ":" + k + l;
								}
							}
						}
					}
				else
					for (int j = 0; j < 3; j++) {
						for (int k = 0; k < 6; k++) {
							for (int l = 0; l <= 9; l++) {
								int t = dist(s, i + "" + j + ":" + k + l);
								if (t < min) {
									min = t;
									ans = i + "" + j + ":" + k + l;
								}
							}
						}
					}
			}
		} else
			for (int i = 0; i <= 2; i++) {
				if (i < 2)
					for (int j = 0; j <= 9; j++) {
						for (int k = 0; k < 6; k++) {
							for (int l = 0; l <= 9; l++) {
								int t = dist(s, i + "" + j + ":" + k + l);
								if (t < min) {
									min = t;
									ans = i + "" + j + ":" + k + l;
								}
							}
						}
					}
				else
					for (int j = 0; j < 4; j++) {
						for (int k = 0; k < 6; k++) {
							for (int l = 0; l <= 9; l++) {
								int t = dist(s, i + "" + j + ":" + k + l);
								if (t < min) {

									min = t;
									ans = i + "" + j + ":" + k + l;
								}
							}
						}

					}
			}
		out.println(ans);

		out.flush();
		out.close();
	}

	static class Scanner {
		StringTokenizer st;
		BufferedReader br;

		public Scanner(InputStream s) {
			br = new BufferedReader(new InputStreamReader(s));
		}

		public String next() throws IOException {
			while (st == null || !st.hasMoreTokens())
				st = new StringTokenizer(br.readLine());
			return st.nextToken();
		}

		public int nextInt() throws IOException {
			return Integer.parseInt(next());
		}

		public long nextLong() throws IOException {
			return Long.parseLong(next());
		}

		public String nextLine() throws IOException {
			return br.readLine();
		}

		public double nextDouble() throws IOException {
			String x = next();
			StringBuilder sb = new StringBuilder("0");
			double res = 0, f = 1;
			boolean dec = false, neg = false;
			int start = 0;
			if (x.charAt(0) == '-') {
				neg = true;
				start++;
			}
			for (int i = start; i < x.length(); i++)
				if (x.charAt(i) == '.') {
					res = Long.parseLong(sb.toString());
					sb = new StringBuilder("0");
					dec = true;
				} else {
					sb.append(x.charAt(i));
					if (dec)
						f *= 10;
				}
			res += Long.parseLong(sb.toString()) / f;
			return res * (neg ? -1 : 1);
		}

		public boolean ready() throws IOException {
			return br.ready();
		}

	}
}


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.StringTokenizer;

public class A {

	public static int dist(String s,String s2){
		int c=0;
		for (int i = 0; i < s.length(); i++) {
			if(s.charAt(i)!=s2.charAt(i))
				c++;
		}
		return c;
	}

	public static void main(String[] args) throws IOException {
		Scanner sc = new Scanner(System.in);
		PrintWriter out = new PrintWriter(System.out);
		int n = sc.nextInt();
		String s=sc.next();
		int min=4;
		String ans="";
		if (n == 12) {
			for (int i = 0; i <= 1; i++) {
				for (int j = 0; (i==0 && j>0&& j <= 9) || (j<3); j++) {
					for (int k = 0; k < 6; k++) {
						for (int l = 0; l <=9; l++) {
							int t=dist(s,i+""+j+":"+k+l);
							if(t<min){
								min=t;
								ans=i+""+j+":"+k+l;
							}
						}
					}
				}
			}
		} else {
			for (int i = 0; i <= 2; i++) {
				for (int j = 0; (i<2 && j <= 9) || (j<4); j++) {
					for (int k = 0; k < 6; k++) {
						for (int l = 0; l <=9; l++) {
							int t=dist(s,i+""+j+":"+k+l);
							if(t<min){
								min=t;
								ans=i+""+j+":"+k+l;
							}
						}
					}
				}
			}
		}
		out.println(ans);

		out.flush();
		out.close();
	}

	static class Scanner {
		StringTokenizer st;
		BufferedReader br;

		public Scanner(InputStream s) {
			br = new BufferedReader(new InputStreamReader(s));
		}

		public String next() throws IOException {
			while (st == null || !st.hasMoreTokens())
				st = new StringTokenizer(br.readLine());
			return st.nextToken();
		}

		public int nextInt() throws IOException {
			return Integer.parseInt(next());
		}

		public long nextLong() throws IOException {
			return Long.parseLong(next());
		}

		public String nextLine() throws IOException {
			return br.readLine();
		}

		public double nextDouble() throws IOException {
			String x = next();
			StringBuilder sb = new StringBuilder("0");
			double res = 0, f = 1;
			boolean dec = false, neg = false;
			int start = 0;
			if (x.charAt(0) == '-') {
				neg = true;
				start++;
			}
			for (int i = start; i < x.length(); i++)
				if (x.charAt(i) == '.') {
					res = Long.parseLong(sb.toString());
					sb = new StringBuilder("0");
					dec = true;
				} else {
					sb.append(x.charAt(i));
					if (dec)
						f *= 10;
				}
			res += Long.parseLong(sb.toString()) / f;
			return res * (neg ? -1 : 1);
		}

		public boolean ready() throws IOException {
			return br.ready();
		}

	}
}


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.StringTokenizer;

public class A {

	public static void main(String[] args) throws IOException {
		Scanner sc = new Scanner(System.in);
		PrintWriter out = new PrintWriter(System.out);
		int n = sc.nextInt();
		String s = sc.next();

		int pre = Integer.parseInt(s.substring(0, 2));
		int post = Integer.parseInt(s.substring(3));
		StringBuilder sb = new StringBuilder();
		if (n == 12) {
			if (pre == 0) {
				sb.append("01");
			} else if (pre > 12 && pre / 10 > 1) {
				sb.append("0" + (((pre%10)==0)? 1:(pre%10)));
			} else if (pre > 12 && pre / 10 == 1) {
				sb.append("10");
			} else
				sb.append(pre<10? "0"+pre :pre);

			sb.append(":");
			if (post >= 60) {
				sb.append("0" + post % 10);
			} else
				sb.append((post<10? "0"+post:post));
		} else {
			if (pre >= 24) {
				sb.append("0" + pre % 10);
			} else
				sb.append(pre<10? "0"+pre:pre);

			sb.append(":");
			if (post >= 60) {
				sb.append("0" + post % 10);
			} else
				sb.append((post)<10? "0"+post:post);
		}

		out.println(sb.toString());

		out.flush();
		out.close();
	}

	static class Scanner {
		StringTokenizer st;
		BufferedReader br;

		public Scanner(InputStream s) {
			br = new BufferedReader(new InputStreamReader(s));
		}

		public String next() throws IOException {
			while (st == null || !st.hasMoreTokens())
				st = new StringTokenizer(br.readLine());
			return st.nextToken();
		}

		public int nextInt() throws IOException {
			return Integer.parseInt(next());
		}

		public long nextLong() throws IOException {
			return Long.parseLong(next());
		}

		public String nextLine() throws IOException {
			return br.readLine();
		}

		public double nextDouble() throws IOException {
			String x = next();
			StringBuilder sb = new StringBuilder("0");
			double res = 0, f = 1;
			boolean dec = false, neg = false;
			int start = 0;
			if (x.charAt(0) == '-') {
				neg = true;
				start++;
			}
			for (int i = start; i < x.length(); i++)
				if (x.charAt(i) == '.') {
					res = Long.parseLong(sb.toString());
					sb = new StringBuilder("0");
					dec = true;
				} else {
					sb.append(x.charAt(i));
					if (dec)
						f *= 10;
				}
			res += Long.parseLong(sb.toString()) / f;
			return res * (neg ? -1 : 1);
		}

		public boolean ready() throws IOException {
			return br.ready();
		}

	}
}


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.StringTokenizer;

public class E {

	public static int dist(String s,String s2){
		int c=0;
		for (int i = 0; i < s.length(); i++) {
			if(s.charAt(i)!=s2.charAt(i))
				c++;
		}
		return c;
	}

	public static void main(String[] args) throws IOException {
		Scanner sc = new Scanner(System.in);
		PrintWriter out = new PrintWriter(System.out);
		int n = sc.nextInt();
		String s=sc.next();
		int min=4;
		String ans="";
		if (n == 12) {
			for (int i = 0; i <= 1; i++) {
				for (int j = 0; (i==0 && j>0 && j <= 9) || (i!=0 && j<3); j++) {
					for (int k = 0; k < 6; k++) {
						for (int l = 0; l <=9; l++) {
							int t=dist(s,i+""+j+":"+k+l);
							if(t<min){
								min=t;
								ans=i+""+j+":"+k+l;
							}
						}
					}
				}
			}
		} else {
			for (int i = 0; i <= 2; i++) {
				for (int j = 0; (i<2 && j <= 9) || (i>=2 && j<4); j++) {
					for (int k = 0; k < 6; k++) {
						for (int l = 0; l <=9; l++) {
							int t=dist(s,i+""+j+":"+k+l);
							if(t<min){
								min=t;
								ans=i+""+j+":"+k+l;
							}
						}
					}
				}
			}
		}
		out.println(ans);

		out.flush();
		out.close();
	}

	static class Scanner {
		StringTokenizer st;
		BufferedReader br;

		public Scanner(InputStream s) {
			br = new BufferedReader(new InputStreamReader(s));
		}

		public String next() throws IOException {
			while (st == null || !st.hasMoreTokens())
				st = new StringTokenizer(br.readLine());
			return st.nextToken();
		}

		public int nextInt() throws IOException {
			return Integer.parseInt(next());
		}

		public long nextLong() throws IOException {
			return Long.parseLong(next());
		}

		public String nextLine() throws IOException {
			return br.readLine();
		}

		public double nextDouble() throws IOException {
			String x = next();
			StringBuilder sb = new StringBuilder("0");
			double res = 0, f = 1;
			boolean dec = false, neg = false;
			int start = 0;
			if (x.charAt(0) == '-') {
				neg = true;
				start++;
			}
			for (int i = start; i < x.length(); i++)
				if (x.charAt(i) == '.') {
					res = Long.parseLong(sb.toString());
					sb = new StringBuilder("0");
					dec = true;
				} else {
					sb.append(x.charAt(i));
					if (dec)
						f *= 10;
				}
			res += Long.parseLong(sb.toString()) / f;
			return res * (neg ? -1 : 1);
		}

		public boolean ready() throws IOException {
			return br.ready();
		}

	}
}


import java.io.*;
import java.util.*;

public class A
{
	public static void main(String[] args) throws IOException
	{
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String n = br.readLine(), s = br.readLine(), hours = s.substring(0, s.indexOf(":")), mins = s.substring(s.indexOf(":")+1);
		br.close();
		int hoursCompare = hours.compareTo(n), minCompare = mins.compareTo("60");
		if(hoursCompare < 0 && minCompare < 0)
			System.out.println(s);
		else if(hoursCompare < 0)
			System.out.println(hours + ":" + "0" + mins.charAt(1));
		else if(minCompare < 0)
			System.out.println("0" + hours.charAt(1) + ":" + mins);
		else
			System.out.println("0" + hours.charAt(1) + ":" + "0" + mins.charAt(1));
	}
}


import java.io.*;
import java.util.*;

public class Main
{
	public static void main(String[] args) throws IOException
	{
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		PrintWriter pw = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)));
		int format = Integer.parseInt(br.readLine());
		String orig = br.readLine();
		if(format == 12)
		{
			int min = 5;
			String minStr = "";
			for(int i = 1; i <= 12; i++)
				for(int j = 0; j <= 59; j++)
				{
					String strHrs = Integer.toString(i);
					if(strHrs.length() == 1)
						strHrs = "0" + strHrs;
					String minHrs = Integer.toString(j);
					if(minHrs.length() == 1)
						minHrs = "0" + minHrs;
					String time = strHrs + ":"  + minHrs;
					int count = 0;
					for(int k = 0; k < 5; k++)
						if(orig.charAt(k) != time.charAt(k))
							count++;
					if(count < min)
					{
						min = count;
						minStr = time;
					}
				}
			pw.println(minStr);
		}
		else
		{
			int min = 5;
			String minStr = "";
			for(int i = 0; i <= 23; i++)
				for(int j = 0; j <= 59; j++)
				{
					String strHrs = Integer.toString(i);
					if(strHrs.length() == 1)
						strHrs = "0" + strHrs;
					String minHrs = Integer.toString(j);
					if(minHrs.length() == 1)
						minHrs = "0" + minHrs;
					String time = strHrs + ":"  + minHrs;
					int count = 0;
					for(int k = 0; k < 5; k++)
						if(orig.charAt(k) != time.charAt(k))
							count++;
					if(count < min)
					{
						min = count;
						minStr = time;
					}
				}
			pw.println(minStr);
		}
		br.close();
		pw.close();
		System.exit(0);
	}
}


import java.io.*;
import java.util.*;

public class A
{
	public static void main(String[] args) throws IOException
	{
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String n = br.readLine(), s = br.readLine(), hours = s.substring(0, s.indexOf(":")), mins = s.substring(s.indexOf(":")+1);
		br.close();
		if(n.equals("12") && hours.equals("00"))
			hours = "01";
		int hoursCompare = hours.compareTo(n), minCompare = mins.compareTo("60");
		if(hoursCompare < 0 && minCompare < 0)
			System.out.println(hours + ":" + mins);
		else if(hoursCompare < 0)
			System.out.println(hours + ":" + "0" + mins.charAt(1));
		else if(minCompare < 0)
			System.out.println("0" + hours.charAt(1) + ":" + mins);
		else
			System.out.println("0" + hours.charAt(1) + ":" + "0" + mins.charAt(1));
	}
}


import java.io.*;
import java.util.*;

public class A
{
	public static void main(String[] args) throws IOException
	{
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String n = br.readLine(), s = br.readLine(), hours = s.substring(0, s.indexOf(":")), mins = s.substring(s.indexOf(":")+1);
		br.close();
		if(n.equals("12") && hours.equals("00"))
			hours = "01";
		int hoursCompare = hours.compareTo(n), minCompare = mins.compareTo("60");
		if(hoursCompare < 0 && minCompare < 0)
			System.out.println(s);
		else if(hoursCompare < 0)
			System.out.println(hours + ":" + "0" + mins.charAt(1));
		else if(minCompare < 0)
			System.out.println("0" + hours.charAt(1) + ":" + mins);
		else
			System.out.println("0" + hours.charAt(1) + ":" + "0" + mins.charAt(1));
	}
}


import java.awt.Point;

import java.util.Comparator;
import java.io.BufferedOutputStream;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.LinkedList;
import java.util.PriorityQueue;
import java.util.Queue;
import java.util.StringTokenizer;
import java.util.TreeMap;
import java.util.TreeSet;

public class Easy2 {
    static char[] alphabet = {'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y','Z'};
    static long mod = (long) (1e9 + 7);
    public static void main(String[] args) {
        MyScanner sc = new MyScanner();
        out = new PrintWriter(new BufferedOutputStream(System.out));
        int n = sc.nextInt();
        String[] curr = sc.nextLine().split(":");
        int hour = Integer.parseInt(curr[0]);
        int min = Integer.parseInt(curr[1]);
        if (min > 59) {
            min = 10 + min%10;
        }
        if (n == 24) {
            if (hour > 29) {
                hour = 10 + hour % 10;
            } else if (hour > 23) {
                hour = 20;
            }
        } else {
            if (hour > 19) {
                hour = hour % 10;
            } else if (hour > 12) {
                hour  = 10;
            } else if (hour == 0) hour = 1;
        }
        out.println((hour < 10 ? "0" : "") + hour + ":" + (min < 10 ? "0" : "")  + min);
        out.close();
    }

    public static PrintWriter out;
    /*
    int n      = sc.nextInt();        // read input as integer
    long k     = sc.nextLong();       // read input as long
    double d   = sc.nextDouble();     // read input as double
    String str = sc.next();           // read input as String
    String s   = sc.nextLine();       // read whole line as String
    out.println(result);              // print via PrintWriter
     */
    public static class MyScanner {
        BufferedReader br;
        StringTokenizer st;

        public MyScanner() {
            br = new BufferedReader(new InputStreamReader(System.in));
        }

        String next() {
            while (st == null || !st.hasMoreElements()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

        int nextInt() {
            return Integer.parseInt(next());
        }

        long nextLong() {
            return Long.parseLong(next());
        }

        double nextDouble() {
            return Double.parseDouble(next());
        }

        String nextLine(){
            String str = "";
            try {
                str = br.readLine();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return str;
        }

    }
}


import java.awt.Point;

import java.util.Comparator;
import java.io.BufferedOutputStream;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.LinkedList;
import java.util.PriorityQueue;
import java.util.Queue;
import java.util.StringTokenizer;
import java.util.TreeMap;
import java.util.TreeSet;

public class Easy2 {
    static char[] alphabet = {'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y','Z'};
    static long mod = (long) (1e9 + 7);
    public static void main(String[] args) {
        MyScanner sc = new MyScanner();
        out = new PrintWriter(new BufferedOutputStream(System.out));
        int n = sc.nextInt();
        String[] curr = sc.nextLine().split(":");
        int hour = Integer.parseInt(curr[0]);
        int min = Integer.parseInt(curr[1]);
        if (min > 59) {
            min = 10 + min%10;
        }
        if (n == 24) {
            if (hour > 29) {
                hour = 10 + hour % 10;
            } else if (hour > 23) {
                hour = 20;
            }
        } else {
            if (hour > 19) {
                hour = hour % 10;
            } else if (hour > 12) {
                hour  = 10;
            }
        }
        out.println((hour < 10 ? "0" : "") + hour + ":" + (min < 10 ? "0" : "")  + min);
        out.close();
    }

    public static PrintWriter out;
    /*
    int n      = sc.nextInt();        // read input as integer
    long k     = sc.nextLong();       // read input as long
    double d   = sc.nextDouble();     // read input as double
    String str = sc.next();           // read input as String
    String s   = sc.nextLine();       // read whole line as String
    out.println(result);              // print via PrintWriter
     */
    public static class MyScanner {
        BufferedReader br;
        StringTokenizer st;

        public MyScanner() {
            br = new BufferedReader(new InputStreamReader(System.in));
        }

        String next() {
            while (st == null || !st.hasMoreElements()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

        int nextInt() {
            return Integer.parseInt(next());
        }

        long nextLong() {
            return Long.parseLong(next());
        }

        double nextDouble() {
            return Double.parseDouble(next());
        }

        String nextLine(){
            String str = "";
            try {
                str = br.readLine();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return str;
        }

    }
}


import java.awt.Point;

import java.util.Comparator;
import java.io.BufferedOutputStream;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.LinkedList;
import java.util.PriorityQueue;
import java.util.Queue;
import java.util.StringTokenizer;
import java.util.TreeMap;
import java.util.TreeSet;

public class Easy2 {
    static char[] alphabet = {'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y','Z'};
    static long mod = (long) (1e9 + 7);
    public static void main(String[] args) {
        MyScanner sc = new MyScanner();
        out = new PrintWriter(new BufferedOutputStream(System.out));
        int n = sc.nextInt();
        String[] curr = sc.nextLine().split(":");
        int hour = Integer.parseInt(curr[0]);
        int min = Integer.parseInt(curr[1]);
        if (min > 59) {
            min = 10 + min%10;
        }
        if (n == 24) {
            if (hour > 29) {
                hour = 10 + hour % 10;
            } else if (hour > 19) {
                hour = 20;
            }
        } else {
            if (hour > 19) {
                hour = hour % 10;
            } else if (hour > 9) {
                hour  = 10;
            }
        }
        out.println((hour < 10 ? "0" : "") + hour + ":" + (min < 10 ? "0" : "")  + min);
        out.close();
    }

    public static PrintWriter out;
    /*
    int n      = sc.nextInt();        // read input as integer
    long k     = sc.nextLong();       // read input as long
    double d   = sc.nextDouble();     // read input as double
    String str = sc.next();           // read input as String
    String s   = sc.nextLine();       // read whole line as String
    out.println(result);              // print via PrintWriter
     */
    public static class MyScanner {
        BufferedReader br;
        StringTokenizer st;

        public MyScanner() {
            br = new BufferedReader(new InputStreamReader(System.in));
        }

        String next() {
            while (st == null || !st.hasMoreElements()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

        int nextInt() {
            return Integer.parseInt(next());
        }

        long nextLong() {
            return Long.parseLong(next());
        }

        double nextDouble() {
            return Double.parseDouble(next());
        }

        String nextLine(){
            String str = "";
            try {
                str = br.readLine();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return str;
        }

    }
}


import java.io.BufferedOutputStream;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.text.DecimalFormat;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.LinkedList;
import java.util.Queue;
import java.util.Stack;
import java.util.StringTokenizer;
import java.util.TreeMap;

public class Easy {
    static long mod = (long) Math.pow(10, 9) + 7;
    static long[][] memo = new long[65][5];

    public static void main(String[] args) {
        MyScanner sc = new MyScanner();
        out = new PrintWriter(new BufferedOutputStream(System.out));

        int n = sc.nextInt();
        String[] curr = sc.nextLine().split(":");
        int hour = Integer.parseInt(curr[0]);
        int min = Integer.parseInt(curr[1]);
        if (min > 59) {
            min = 10 + min%10;
        }
        if (n == 24) {
            if (hour > 29) {
                hour = 10 + hour % 10;
            } else if (hour > 23) {
                hour = 20;
            }
        } else {
            if (hour > 19) {
                hour = hour % 10;
                if (hour == 0) hour = 10;
            } else if (hour > 12) {
                hour  = 10;
            } else if (hour == 0) hour = 1;
        }
        out.println((hour < 10 ? "0" : "") + hour + ":" + (min < 10 ? "0" : "")  + min);
        out.close();
    }

    public static class Node {
        HashMap<Integer, Integer> edges;
        public Node() {
            edges = new HashMap<>();
        }
    }

    public static long[] matPow(int pow) {
        long[] mat = new long[4];
        if (memo[pow][0] != 0) {
            mat[0] = memo[pow][1];
            mat[1] = memo[pow][2];
            mat[2] = memo[pow][3];
            mat[3] = memo[pow][4];
            return mat;
        }

        long[] temp = matPow(pow - 1);
        long[] temp2 = matPow(pow - 1);
        mat[0] = (temp[0]*temp2[0] + temp[1]*temp2[2]) % mod;
        mat[1] = (temp[0]*temp2[1] + temp[1]*temp2[3]) % mod;
        mat[2] = (temp[2]*temp2[0] + temp[3]*temp2[2]) % mod;
        mat[3] = (temp[2]*temp2[1] + temp[3]*temp2[3]) % mod;
        memo[pow][0] = 1;
        memo[pow][1] = mat[0];
        memo[pow][2] = mat[1];
        memo[pow][3] = mat[2];
        memo[pow][4] = mat[3];
        return mat;
    }

    public static PrintWriter out;
    /*
    int n      = sc.nextInt();        // read input as integer
    long k     = sc.nextLong();       // read input as long
    double d   = sc.nextDouble();     // read input as double
    String str = sc.next();           // read input as String
    String s   = sc.nextLine();       // read whole line as String
    out.println(result);              // print via PrintWriter
     */
    public static class MyScanner {
        BufferedReader br;
        StringTokenizer st;

        public MyScanner() {
            br = new BufferedReader(new InputStreamReader(System.in));
        }

        String next() {
            while (st == null || !st.hasMoreElements()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

        int nextInt() {
            return Integer.parseInt(next());
        }

        long nextLong() {
            return Long.parseLong(next());
        }

        double nextDouble() {
            return Double.parseDouble(next());
        }

        String nextLine(){
            String str = "";
            try {
                str = br.readLine();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return str;
        }

    }
}


import java.awt.Point;

import java.util.Comparator;
import java.io.BufferedOutputStream;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.LinkedList;
import java.util.PriorityQueue;
import java.util.Queue;
import java.util.StringTokenizer;
import java.util.TreeMap;
import java.util.TreeSet;

public class Easy2 {
    static char[] alphabet = {'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y','Z'};
    static long mod = (long) (1e9 + 7);
    public static void main(String[] args) {
        MyScanner sc = new MyScanner();
        out = new PrintWriter(new BufferedOutputStream(System.out));
        int n = sc.nextInt();
        String[] curr = sc.nextLine().split(":");
        int hour = Integer.parseInt(curr[0]);
        int min = Integer.parseInt(curr[1]);
        String pre = "";
        if (min > 59) {
            min = 10 + min%10;
        }
        if (n == 24) {
            if (hour > 29) {
                hour = 10 + hour % 10;
            } else if (hour > 19) {
                hour = 20;
            }
        } else {
            if (hour > 19) {
                hour = hour % 10;
                pre = "0";
            } else if (hour > 9) {
                hour  = 10;
            }
        }
        out.println(pre + hour + ":" + min);
        out.close();
    }

    public static PrintWriter out;
    /*
    int n      = sc.nextInt();        // read input as integer
    long k     = sc.nextLong();       // read input as long
    double d   = sc.nextDouble();     // read input as double
    String str = sc.next();           // read input as String
    String s   = sc.nextLine();       // read whole line as String
    out.println(result);              // print via PrintWriter
     */
    public static class MyScanner {
        BufferedReader br;
        StringTokenizer st;

        public MyScanner() {
            br = new BufferedReader(new InputStreamReader(System.in));
        }

        String next() {
            while (st == null || !st.hasMoreElements()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

        int nextInt() {
            return Integer.parseInt(next());
        }

        long nextLong() {
            return Long.parseLong(next());
        }

        double nextDouble() {
            return Double.parseDouble(next());
        }

        String nextLine(){
            String str = "";
            try {
                str = br.readLine();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return str;
        }

    }
}