#include <bits/stdc++.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);
  return 0;
}
