#include <bits/stdc++.h>
using namespace std;
const int iinf = 1e9 + 7;
const long long linf = 1ll << 60;
const double dinf = 1e10;
inline long long read() {
  bool f = 0;
  long long x = 0;
  char c = getchar();
  while ((c < '0' || c > '9') && c != '-') c = getchar();
  if (c == '-') {
    f = 1;
    c = getchar();
  }
  while (c >= '0' && c <= '9') {
    x = x * 10 + c - '0';
    c = getchar();
  }
  if (f) x = -x;
  return x;
}
inline void scf(int &x) {
  bool f = 0;
  x = 0;
  char c = getchar();
  while ((c < '0' || c > '9') && c != '-') c = getchar();
  if (c == '-') {
    f = 1;
    c = getchar();
  }
  while (c >= '0' && c <= '9') {
    x = x * 10 + c - '0';
    c = getchar();
  }
  if (f) x = -x;
  return;
}
void scf(int &x, int &y) {
  scf(x);
  return scf(y);
}
void scf(int &x, int &y, int &z) {
  scf(x);
  scf(y);
  return scf(z);
}
int n;
int h, m;
void out(int x) {
  if (!x) {
    printf("00");
    return;
  }
  if (x < 10) printf("0");
  printf("%d", x);
  return;
}
int main() {
  scf(n);
  scanf("%d:%d", &h, &m);
  if (m >= 60) m %= 10;
  if (n == 24) {
    if (h > 23) h %= 10;
  } else if (h < 1 || h > 12) {
    h %= 10;
    if (!h) h = 10;
  }
  out(h);
  putchar(':');
  out(m);
  putchar('\n');
  return 0;
}
