#include <bits/stdc++.h>
using namespace std;
template <class T1, class T2>
bool upmin(T1 &x, T2 v) {
  if (x > v) {
    x = v;
    return true;
  }
  return false;
}
template <class T1, class T2>
bool upmax(T1 &x, T2 v) {
  if (x < v) {
    x = v;
    return true;
  }
  return false;
}
void solve() {
  int N;
  cin >> N;
  if (N == 12) {
    string s;
    cin >> s;
    int h = (s[0] - '0') * 10 + (s[1] - '0');
    int m = (s[3] - '0') * 10 + (s[4] - '0');
    while (h > 12) h -= 10;
    while (h < 1) h += 10;
    while (m > 59) m -= 10;
    if (h < 10) cout << "0";
    cout << h << ":";
    if (m < 10) cout << "0";
    cout << m << endl;
  } else {
    string s;
    cin >> s;
    int h = (s[0] - '0') * 10 + (s[1] - '0');
    int m = (s[3] - '0') * 10 + (s[4] - '0');
    while (h > 23) h -= 10;
    while (m > 59) m -= 10;
    if (h < 10) cout << "0";
    cout << h << ":";
    if (m < 10) cout << "0";
    cout << m << endl;
  }
}
int main() {
  ios::sync_with_stdio(false);
  solve();
  return 0;
}
