#include <bits/stdc++.h>
using namespace std;
char foo[10];
int main() {
  int x;
  scanf("%d", &x);
  int h, m;
  scanf("%d:%d", &h, &m);
  if (x == 12) {
    if (h == 0)
      h++;
    else if (h > 12) {
      while (h > 12) h -= 10;
    }
  } else {
    if (h > 23) {
      while (h > 23) h -= 10;
    }
  }
  while (m >= 60) m -= 10;
  printf("%02d:%02d\n", h, m);
  return 0;
}
