#include <bits/stdc++.h>
using namespace std;
int main() {
  int t;
  cin >> t;
  string time;
  cin >> time;
  if (t == 24) {
    if (time[3] > '5') time[3] = '0';
    if (time[0] != '0' && time[0] != '1' && time[0] != '2') time[0] = '0';
    if (time[0] == '2' && !(time[1] >= '0' && time[1] <= '3')) time[1] = '0';
  } else {
    if (time[3] > '5') time[3] = '0';
    if (time[0] > '1' && time[1] == '0') time[0] = '1';
    if (time[0] > '1') time[0] = '0';
    if (time[0] == '0' && time[1] == '0') time[1] = '1';
    if (time[0] == '1' && time[1] > '2') time[1] = '1';
  }
  cout << time << endl;
  return 0;
}
