#include <bits/stdc++.h>
using namespace std;
bool debug = 0;
int n, m, k;
int dx[4] = {0, 1, 0, -1}, dy[4] = {1, 0, -1, 0};
string direc = "RDLU";
long long ln, lk, lm;
void etp(bool f = 0) {
  puts(f ? "YES" : "NO");
  exit(0);
}
void addmod(int &x, int y, int mod = 1000000007) {
  x += y;
  if (x >= mod) x -= mod;
  assert(x >= 0 && x < mod);
}
void et() {
  puts("-1");
  exit(0);
}
char s[10];
void fmain() {
  scanf("%d", &n);
  scanf("%s", s);
  if (s[3] - '0' > 5) s[3] = '0';
  if (n == 12) {
    if (s[0] == '0') {
      if (s[1] == '0') s[1] = '1';
    } else if (s[0] == '1') {
      if (s[1] != '0' && s[1] != '1' && s[1] != '2') s[1] = '1';
    } else {
      if (s[1] == '0')
        s[0] = '1';
      else
        s[0] = '0';
    }
  } else {
    if (s[0] == '2') {
      if (s[1] - '0' > 3) s[1] = '0';
    } else if (s[0] - '0' > 2)
      s[0] = '0';
  }
  puts(s);
}
int main() {
  int t = 1;
  for (int(i) = 1; (i) <= (int)(t); (i)++) fmain();
  return 0;
}
