#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  string s;
  cin >> s;
  if (n == 12) {
    string hour = "";
    hour += s[0];
    hour += s[1];
    string min = "";
    min += s[3];
    min += s[4];
    if (hour == "00") s[0] = '1';
    if (stoi(hour) > 12) {
      if (s[1] == '0')
        s[0] = '1';
      else if (s[1] == '2' || s[1] == '1')
        s[0] = '1';
      else {
        s[0] = '0';
      }
    }
    if (stoi(min) > 59) {
      s[3] = '0';
    }
  } else {
    string hour = "";
    hour += s[0];
    hour += s[1];
    string min = "";
    min += s[3];
    min += s[4];
    if (stoi(hour) > 23) {
      s[0] = '0';
    }
    if (stoi(min) > 59) s[3] = '0';
  }
  cout << s << endl;
  return 0;
}
