#include <bits/stdc++.h>
using namespace std;
template <class T>
inline T bigmod(T b, T p, T M) {
  long long ret = 1;
  for (; p > 0; p >>= 1) {
    if (p & 1) ret = (ret * b) % M;
    b = (b * b) % M;
  }
  return (T)ret;
}
template <class T>
inline T lcm(T a, T b) {
  return (a * b) / __gcd(a, b);
}
int dx4[] = {1, 0, -1, 0};
int dy4[] = {0, 1, 0, -1};
int dx8[] = {0, 0, 1, 1, 1, -1, -1, -1};
int dy8[] = {1, -1, -1, 0, 1, -1, 0, 1};
int kx8[] = {1, 1, 2, 2, -1, -1, -2, -2};
int ky8[] = {2, -2, 1, -1, 2, -2, 1, -1};
const double PI = acos(-1.0), EPS = 1e-7;
const long long INF = (long long)1e18 + 7;
const int N = 2e5 + 5, M = 1e9 + 7;
int fmt;
string s;
int main() {
  cin >> fmt >> s;
  if (fmt == 12) {
    if (s[0] == '0' && s[1] == '0') s[0] = '1';
    if (s[0] > '1') {
      if (s[1] == '0')
        s[0] = '1';
      else
        s[0] = '0';
    }
    if (s[0] == '1' && s[1] > '2') s[1] = '0';
    if (s[3] >= '6') s[3] = '0';
  } else {
    if (s[0] > '2') s[0] = '0';
    if (s[0] == '2' && s[1] >= '4') s[0] = '0';
    if (s[3] >= '6') s[3] = '0';
  }
  cout << s << endl;
  return 0;
}
