#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  string s;
  cin >> s;
  int h = (s[0] - '0') * 10 + s[1] - '0';
  int m = (s[3] - '0') * 10 + s[4] - '0';
  if (n == 12) {
    if (h == 0)
      s[1] = '1';
    else if (h % 10 == 0)
      s[0] = '1';
    else if (h > 12)
      s[0] = '0';
    if (m >= 60) s[3] = '0';
  } else {
    if (h >= 24) s[0] = '0';
    if (m >= 60) s[3] = '0';
  }
  cout << s;
}
