#include <bits/stdc++.h>
using namespace std;
int n;
int cal(int x, int y) {
  int res = 0;
  res += (x % 10) != (y % 10);
  res += (x / 10) != (y / 10);
  return res;
}
string ti(int x, int y) {
  string res = "";
  res.push_back(char((x / 10) + '0'));
  res.push_back(char((x % 10) + '0'));
  res.push_back(':');
  res.push_back(char((y / 10) + '0'));
  res.push_back(char((y % 10) + '0'));
  return res;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  string line;
  getline(cin, line);
  stringstream ss(line);
  ss >> n;
  string t;
  int res = 200;
  string opt = "";
  getline(cin, t);
  int h = (t[0] - '0') * 10 + (t[1] - '0');
  int m = (t[3] - '0') * 10 + (t[4] - '0');
  for (int i = ((n == 12) ? 1 : 0); i <= ((n == 12) ? 12 : 23); ++i) {
    for (int j = 0; j < 60; ++j) {
      int tmp = cal(h, i) + cal(m, j);
      res = min(res, tmp);
      if (res == tmp) {
        opt = ti(i, j);
      }
    }
  }
  cout << opt << endl;
  return 0;
}
