#include <bits/stdc++.h>
using namespace std;
int main() {
  int f;
  cin >> f;
  string g;
  cin >> g;
  if (f == 12) {
    if (g[0] > '1' && g[1] > '0')
      g[0] = '0';
    else if (g[0] > '1' && g[1] == '0')
      g[0] = '1';
    else if (g[0] == '1' && g[1] > '2')
      g[0] = '0';
    else if (g[0] == '0' && g[1] < '1')
      g[0] = '1';
    else
      g[0] = g[0];
    if (g[3] > '5')
      g[3] = '5';
    else
      g[3] = g[3];
  }
  if (g[0] > '2')
    g[0] = '0';
  else if (g[0] == '2' && g[1] > '3')
    g[1] = '3';
  else
    g[1] = g[1];
  if (g[3] > '5')
    g[3] = '5';
  else
    g[3] = g[3];
  cout << g << endl;
}
