#include <bits/stdc++.h>
using namespace std;
int main() {
  int t, h, m;
  cin >> t;
  scanf("%d:%d", &h, &m);
  while (m > 59) m -= 10;
  if (t == 24) {
    while (h > 23) h -= 10;
  } else if (t == 12) {
    while (h > 12) h -= 10;
    if (h == 0) h++;
  }
  printf("%02d:%02d\n", h, m);
}
