#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, orari[201], dist, massimo = 0, h, m;
  string s;
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> s;
    orari[2 * i] =
        60 * (10 * (s[0] - '0') + s[1] - '0') + 10 * (s[3] - '0') + s[4] - '0';
    orari[2 * i + 1] = orari[2 * i] + 1440;
  }
  sort(orari, orari + 2 * n);
  for (int i = 1; i < 2 * n; i++) {
    dist = orari[i] - orari[i - 1];
    massimo = max(massimo, dist);
  }
  h = massimo / 60;
  m = massimo % 60 - 1;
  if (m < 0) {
    if (h == 0)
      cout << "00:00";
    else {
      h--;
      m = 59;
    }
  }
  if (h < 10) cout << 0;
  cout << h << ":";
  if (m < 10) cout << 0;
  cout << m;
  return 0;
}
