#include <bits/stdc++.h>
using namespace std;
int main() {
  int mod, h, m;
  char c;
  cin >> mod >> h >> c >> m;
  if (mod == 12) {
    if (h == 0) {
      cout << "01";
    } else if (h <= 12) {
      if (h < 10) cout << 0;
      cout << h;
    } else if (h > 12) {
      if (h % 10 == 0)
        cout << 10;
      else
        cout << 0 << h % 10;
    }
    cout << ':';
  }
  if (mod == 24) {
    if (h <= 23) {
      if (h < 10) cout << 0;
      cout << h;
    } else if (h > 23) {
      cout << 0 << h % 10;
    }
    cout << ':';
  }
  if (m >= 60)
    cout << 0 << m % 10;
  else {
    if (m < 10) cout << 0;
    cout << m;
  }
}
