#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  string s;
  cin >> s;
  int a = s[0] - 48, b = s[1] - 48, c = s[3] - 48, d = s[4] - 48;
  int x = 10 * a + b, y = 10 * c + d;
  if (n == 12) {
    if (x > 12) {
      if (b == 0) {
        a = 1;
      } else
        a = 0;
    } else if (x == 0)
      b = 1;
    if (y > 59) {
      if (d == 0)
        c = 1;
      else
        c = 0;
    }
  } else if (n == 24) {
    if (x > 23) {
      if (b == 0) {
        a = 1;
      } else
        a = 0;
    }
    if (y > 59) {
      if (d == 0)
        c = 1;
      else
        c = 0;
    }
  }
  cout << a << b << ':' << c << d;
}
