#include <bits/stdc++.h>
using namespace std;
int main() {
  int hours;
  cin >> hours;
  int h, m;
  cin >> h;
  cin.ignore();
  cin >> m;
  while (m > 59) m -= 10;
  if (hours == 24) {
    while (h > 23) {
      h -= 10;
    }
  } else {
    while (h > 12) {
      h -= 10;
    }
    if (!h) {
      h = 10;
    }
  }
  if (h < 10) cout << '0';
  cout << h;
  cout << ':';
  if (m < 10) cout << '0';
  cout << m;
  return 0;
}
