#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:256000000")
using namespace std;
const double EPS = 1e-9;
const double pi = acos(-1.0);
const long long MAXN = (long long)1e6 + 7;
const long long INF = (long long)1e9 + 7;
const long long LINF = (long long)1 << 63 - 5;
const long long MOD = (long long)2147482661;
const long long P = 239017;
const long long SZ = (long long)1e5;
int a[MAXN], pos[MAXN], b[MAXN];
vector<int> ans;
map<int, int> mpr, mpl, suml, sumr;
int main() {
  int n;
  string s;
  cin >> n;
  cin >> s;
  if (s[3] >= '6') s[3] = '0';
  if (n == 12) {
    if (s[0] == '0' && s[1] == '0') {
      s[1] = '1';
    } else {
      if (s[0] > '1' || (s[0] == '1' && s[1] > '2')) {
        if (s[1] != '0') {
          s[0] = '0';
        } else {
          s[0] = '1';
        }
      }
    }
  }
  if (n == 24) {
    if (s[0] > '2' || s[0] == '2' && s[1] >= '4') s[0] = '0';
  }
  cout << s;
}
