#include <bits/stdc++.h>
using namespace std;
int main() {
  int t;
  char s[10];
  scanf("%d %s", &t, s);
  if (t == 12) {
    if (s[0] > '1' || (s[0] == '1' && s[1] >= '3')) s[0] = '0';
    if ((s[0] == '0') && (s[1] == '0')) s[0] = '1';
    if (s[3] > '5') s[3] = '0';
  } else {
    if (s[0] > '2' || (s[0] == '2' && s[1] >= '4')) s[0] = '0';
    if (s[3] > '5') s[3] = '0';
  }
  printf("%s\n", s);
  return 0;
}
