#include <bits/stdc++.h>
using namespace std;
long i, j, m, n, p, q, r, s, a, b;
string aa, bb;
int main() {
  cin >> n;
  scanf("%ld:%ld", &a, &b);
  if (n == 12) {
    if (a == 0)
      aa = "01";
    else if (a >= 13) {
      p = a % 10;
      if (p == 0) {
        aa = "10";
      } else
        aa += '0', aa += (a % 10 + 48);
    } else {
      p = a % 10;
      a /= 10;
      q = a % 10;
      aa += (q + 48), aa += (p + 48);
    }
    if (b == 60)
      bb = "00";
    else if (b > 60) {
      bb += '0', bb += (b % 10 + 48);
    } else {
      p = b % 10;
      b /= 10;
      q = b % 10;
      bb += (q + 48), bb += (p + 48);
    }
    cout << aa << ":" << bb;
  } else {
    if (a >= 24) {
      aa += '0', aa += (a % 10 + 48);
    } else {
      p = a % 10;
      a /= 10;
      q = a % 10;
      aa += (q + 48), aa += (p + 48);
    }
    if (b == 60)
      bb = "00";
    else if (b > 60) {
      bb += '0', bb += (b % 10 + 48);
    } else {
      p = b % 10;
      b /= 10;
      q = b % 10;
      bb += (q + 48), bb += (p + 48);
    }
    cout << aa << ":" << bb;
  }
}
