#include <bits/stdc++.h>
using namespace std;
int n = 0;
string s = "";
int main() {
  cin >> n >> s;
  if (n == 12) {
    if (s.substr(0, 2) == "00")
      s[1] = '1';
    else if (s.substr(0, 2) > "12")
      s[0] = s[1] == '0' ? '1' : '0';
  } else if (s.substr(0, 2) > "23")
    s[0] = '0';
  if (s.substr(3, 5) > "59") s[3] = '0';
  cout << s;
}
