#include <bits/stdc++.h>
using namespace std;
void solve(int tp) {
  assert(tp == 12 || tp == 24);
  string tm;
  cin >> tm;
  assert((int)(tm).size() == 5 && tm[2] == ':');
  int bst = 10;
  string ans = "";
  for (int rm = 0; rm < 60; rm++) {
    int l = (tp == 12 ? 1 : 0);
    int r = (tp == 12 ? 13 : 24);
    for (int rh = l; rh < r; rh++) {
      string cur;
      cur += (rh / 10) + '0';
      cur += (rh % 10) + '0';
      cur += ':';
      cur += (rm / 10) + '0';
      cur += (rm % 10) + '0';
      int cnt = 0;
      for (int i = 0; i < 5; i++) cnt += (cur[i] != tm[i]);
      if (cnt < bst) bst = cnt, ans = cur;
    }
  }
  cout << ans << endl;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  int n;
  while (cin >> n) solve(n);
}
