#include <bits/stdc++.h>
using namespace std;
using ii = pair<long long int, long long int>;
class prioritize {
 public:
  bool operator()(ii &p1, ii &p2) { return p1.first < p2.first; }
};
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  long long int n;
  cin >> n;
  string s;
  cin >> s;
  long long int l1 = s[0] - '0';
  long long int l2 = s[1] - '0';
  long long int r2 = s[3] - '0';
  long long int r1 = s[4] - '0';
  long long int cc = 0;
  if (n == 12) {
    if (r2 >= 6) {
      r2 = 1;
      cc++;
    }
    if (l2 > 2 || l1 > 1) {
      if (l2 > 0)
        l1 = 0;
      else
        l1 = 1;
      cc++;
    }
    if (l1 == 0 && l2 == 0) {
      cc++;
      l2 = 1;
    }
    cout << l1 << l2 << ":" << r2 << r1 << "\n";
  } else {
    if (r2 >= 6) {
      r2 = 1;
      cc++;
    }
    if (l1 == 2 && (l2 >= 4)) {
      l1 = 0;
      cc++;
    }
    if (l1 > 2) {
      l1 = 0;
      cc++;
    }
    cout << l1 << l2 << ":" << r2 << r1 << "\n";
  }
}
