#include <bits/stdc++.h>
using namespace std;
using ll = long long int;
int ar[101];
int main() {
  int n, ans;
  string t;
  while (cin >> n >> t) {
    int h, m;
    if (n == 12) {
      h = (t[0] - '0') * 10 + (t[1] - '0');
      m = (t[3] - '0') * 10 + (t[4] - '0');
      if (t[0] == '0' && t[1] == '0')
        t[1] = '1';
      else if (t[0] == '1' && t[1] > '2')
        t[1] = '1';
      else if (t[0] > '1' && t[1] != '0')
        t[0] = '0';
      else if (t[0] > '1' && t[1] == '0')
        t[0] = '1';
      if (t[3] > '5') t[3] = '0';
    } else {
      h = (t[0] - '0') * 10 + (t[1] - '0');
      m = (t[3] - '0') * 10 + (t[4] - '0');
      if (t[0] > '2')
        t[0] = '0';
      else if (t[0] == '2' && t[1] > '3')
        t[1] = '1';
      else if (t[0] > '3')
        t[0] = '0';
      if (t[3] > '5') t[3] = '0';
    }
    cout << t << "\n";
  }
  return 0;
}
