#include <bits/stdc++.h>
using namespace std;
int main() {
  int num;
  string str;
  cin >> num;
  cin >> str;
  if (str[3] >= '6') str[3] = '0';
  if (num == 12) {
    if (str[0] >= '2' || (str[0] == '1' && str[1] > '2') ||
        (str[0] == '0' && str[1] == '0')) {
      str[0] = '0';
      if (str[1] == '0') str[0] = '1';
    }
  } else if (num == 24) {
    if (str[0] >= '3' || (str[0] == '2' && str[1] >= '4')) str[0] = '0';
  }
  cout << str << endl;
}
