#include <bits/stdc++.h>
using namespace std;
int main() {
  long form, hh, mm;
  char colon;
  cin >> form >> hh >> colon >> mm;
  if (mm >= 60) mm = 50 + (mm % 10);
  if (form == 12) {
    if (hh > 12) hh %= 10;
    if (hh == 0) hh = 10;
  } else {
    if (hh >= 24) hh %= 10;
  }
  cout << setfill('0') << setw(2) << hh << ":" << setfill('0') << setw(2) << mm
       << endl;
}
