#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  int format;
  cin >> format;
  string t;
  cin >> t;
  vector<int> time{t[0] - '0', t[1] - '0', t[3] - '0', t[4] - '0'};
  if (format == 12) {
    if (time[0] > 1) {
      t[0] = '0';
      time[0] = 0;
      if (time[1] == 0) {
        t[0] = '1';
        time[0] = 1;
      }
    }
    if (time[0] == 1) {
      if (time[1] > 2) {
        t[1] = '2';
      }
    }
    if (time[0] == 0 && time[1] == 0) {
      t[1] = '1';
    }
  } else {
    if (time[0] > 2) {
      t[0] = '0';
      time[0] = 0;
    }
    if (time[0] == 2) {
      if (time[1] > 3) {
        t[1] = '3';
      }
    }
  }
  if (time[2] > 5) {
    t[3] = '0';
  }
  cout << t << endl;
}
