#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(0);
  int h, m, t;
  char f;
  cin >> t;
  cin >> h >> f >> m;
  if (t == 24) {
    int a = h / 10 % 10;
    int b = h % 10;
    if (a > 2) a = 1;
    if (a == 2 && b >= 4) b = 1;
    h = 10 * a + b;
    a = m / 10 % 10;
    b = m % 10;
    if (m > 59) a = 1;
    m = a * 10 + b;
  } else {
    int a = h / 10 % 10;
    int b = h % 10;
    if (a == 1 && b > 2)
      a = 0;
    else if (a == 0 && b == 0)
      b = 1;
    else if (a > 1 && b != 0)
      a = 0;
    else if (a > 1 && b == 0) {
      a = 1;
    }
    h = a * 10 + b;
    a = m / 10 % 10;
    b = m % 10;
    if (m > 59) a = 1;
    m = a * 10 + b;
  }
  if (h == 0)
    cout << "00";
  else if (h < 10)
    cout << "0" << h;
  else
    cout << h;
  cout << ":";
  if (m == 0)
    cout << "00";
  else if (m < 10)
    cout << "0" << m;
  else
    cout << m;
  return 0;
}
