#include <bits/stdc++.h>
using namespace std;
int main(int argc, char** argv) {
  int a, b, clock[2], mode, min[2];
  char c;
  do {
    cin >> mode;
  } while (mode != 12 && mode != 24);
  cin >> a >> c >> b;
  clock[0] = a / 10;
  clock[1] = a % 10;
  min[0] = b / 10;
  min[1] = b % 10;
  if (b > 59) {
    b -= 40;
    min[0] = b / 10;
    min[1] = b % 10;
  }
  if (mode == 12 && (a > 12 || a == 0)) {
    if (clock[1] == 0)
      clock[0] = 1;
    else
      clock[0] = 0;
  }
  if (mode == 24 && a > 23) clock[0] = 0;
  cout << clock[0] << clock[1] << c << min[0] << min[1];
  return 0;
}
