#include <bits/stdc++.h>
using namespace std;
int diff, adiff;
char answ[10];
char inp[10];
char gen[10];
void Test(int h, int m) {
  gen[0] = h / 10 + '0';
  gen[1] = h % 10 + '0';
  gen[2] = ':';
  gen[3] = m / 10 + '0';
  gen[4] = m % 10 + '0';
  gen[5] = '\0';
  int diff = 0;
  for (int i = 0; i < 5; i++) {
    if (gen[i] != inp[i]) diff++;
  }
  if (diff < adiff) {
    adiff = diff;
    for (int i = 0; i < 6; i++) {
      answ[i] = gen[i];
    }
  }
}
int main() {
  int format;
  adiff = 10;
  scanf("%d", &format);
  scanf("%s", inp);
  if (format == 24) {
    for (int h = 0; h < 24; h++) {
      for (int m = 0; m < 60; m++) {
        Test(h, m);
      }
    }
  } else {
    for (int h = 1; h <= 12; h++) {
      for (int m = 0; m < 60; m++) {
        Test(h, m);
      }
    }
  }
  printf("%s\n", answ);
  return 0;
}
