#include <bits/stdc++.h>
int main() {
  int a, b, c;
  scanf("%d", &c);
  scanf("%02d:%02d", &a, &b);
  if (b >= 60) b %= 10;
  if (a > c || a == 24) a %= 10;
  if (c == 12 && a == 0) a = 10;
  printf("%02d:%02d", a, b);
}
