#include <bits/stdc++.h>
using namespace std;
int main() {
  int a, b, p, q, i, k;
  char me[6], me1[6];
  scanf("%d", &a);
  scanf("%s", me);
  if (a == 12) {
    p = 0;
    i = 0;
    p = (p * 10) + (me[0] - '0');
    p = (p * 10) + (me[1] - '0');
    if (!p) {
      me1[i++] = me[0];
      me1[i++] = 1 + '0';
    } else if (p > 12) {
      if (me[1] == '0') {
        me1[i++] = 1 + '0';
        me1[i++] = 0 + '0';
      } else if (me[1] != 0) {
        me1[i++] = 0 + '0';
        me1[i++] = me[1];
      }
    } else {
      me1[i++] = me[0];
      me1[i++] = me[1];
    }
  } else {
    p = 0;
    i = 0;
    p = (p * 10) + (me[0] - '0');
    p = (p * 10) + (me[1] - '0');
    if (!p) {
      me1[i++] = me[0];
      me1[i++] = 0 + '0';
    } else if (p > 23) {
      if (me[1] == '0') {
        me1[i++] = 1 + '0';
        me1[i++] = 0 + '0';
      } else if (me[1] != 0) {
        me1[i++] = 0 + '0';
        me1[i++] = me[1];
      }
    } else {
      me1[i++] = me[0];
      me1[i++] = me[1];
    }
  }
  me1[i++] = ':';
  a = 0;
  a = (a * 10) + (me[3] - '0');
  a = (a * 10) + (me[4] - '0');
  if (a > 59) {
    if (me[4] != 0) {
      me1[i++] = 0 + '0';
      me1[i++] = me[4];
    } else {
      me1[i++] = 0 + '0';
      me1[i++] = 1 + '0';
    }
  } else {
    me1[i++] = me[3];
    me1[i++] = me[4];
  }
  for (i = 0; i < 5; i++) {
    printf("%c", me1[i]);
  }
  cout << endl;
  return 0;
}
