#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(0);
  int n;
  cin >> n;
  string s;
  cin >> s;
  int h = 10 * (s[0] - '0') + (s[1] - '0');
  int m = 10 * (s[3] - '0') + (s[4] - '0');
  if (n == 24) {
    if (h < 0 || h >= 24) h = h % 10 + 10;
  } else {
    if (h < 1 || h > 12) {
      if (h % 10 == 0) {
        h = 10;
      } else {
        h = h % 10;
      }
    }
  }
  if (m < 0 || m > 59) {
    m = m % 10;
  }
  if (h < 10) cout << "0";
  cout << h << ":";
  if (m < 10) cout << "0";
  cout << m;
  return 0;
}
