#include <bits/stdc++.h>
using namespace std;
const double pi = acos(-1);
const long long mo = 1e9 + 7;
const int oo = 1 << 30;
struct edge {
  int u, v;
  int w;
  edge() { u = v = w = 0; }
  edge(int a, int b, int c) : u(a), v(b), w(c) {}
};
int main() {
  int type;
  cin >> type;
  string s;
  cin >> s;
  int ans = 0;
  if (s[3] >= '6') {
    s[3] = '0';
  }
  int f = stoi(s.substr(0, 2));
  if (type == 12) {
    if (f == 0) {
      s[0] = '1';
    } else if (f > 12) {
      if (f % 10 == 0) {
        s[0] = '1';
      } else {
        s[0] = '0';
      }
    }
  } else {
    if (f >= 24) {
      s[0] = '1';
    }
  }
  cout << s;
  return 0;
}
