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