#include <vector>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <cstring>
#include <math.h>
#define lli long long int
using namespace std;
int main(){
int f;
cin >> f;
string x;
cin >> x;
int a[5];
string r;
for(int i = 0; i < 5; i++){
if(i == 2){
continue;
}
r = x[i];
a[i] = std::stoi(r);
}
int hours = (a[0] * 10) + a[1];
int minutes = (a[3] * 10) + a[1];
if(f==12){
if(a[0] == 0){
if(a[1] == 0){
a[1] = 1;
}
}
if(a[0] > 1){
a[0] = 1;
}
if(a[1] > 2){
a[1] = 2;
}
if(a[3] > 5){
a[3] = 5;
}
}
else{
if(a[0] > 2){
a[0] = 0;
}
else if(a[0]== 2){
if(a[1] > 3){
a[1] = 0;
}
}
if(a[3] > 5){
a[3] = 5;
}
}
for(int i = 0; i < 5; i++){
if(i == 2){
cout << ":";
continue;
}
cout << a[i];
}
}
I2luY2x1ZGUgPHZlY3Rvcj4KI2luY2x1ZGUgPGxpc3Q+CiNpbmNsdWRlIDxtYXA+CiNpbmNsdWRlIDxzZXQ+CiNpbmNsdWRlIDxxdWV1ZT4KI2luY2x1ZGUgPGRlcXVlPgojaW5jbHVkZSA8c3RhY2s+CiNpbmNsdWRlIDxiaXRzZXQ+CiNpbmNsdWRlIDxhbGdvcml0aG0+CiNpbmNsdWRlIDxmdW5jdGlvbmFsPgojaW5jbHVkZSA8bnVtZXJpYz4KI2luY2x1ZGUgPHV0aWxpdHk+CiNpbmNsdWRlIDxzc3RyZWFtPgojaW5jbHVkZSA8aW9zdHJlYW0+CiNpbmNsdWRlIDxpb21hbmlwPgojaW5jbHVkZSA8Y3N0ZGlvPgojaW5jbHVkZSA8Y21hdGg+CiNpbmNsdWRlIDxjc3RkbGliPgojaW5jbHVkZSA8Y3RpbWU+CiNpbmNsdWRlIDxjc3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