#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, h, m;
  string s;
  cin >> n;
  vector<pair<int, int> > v;
  for (int i = 0; i < n; ++i) {
    cin >> s;
    h = (s[0] - '0') * 10 + s[1] - '0';
    m = (s[3] - '0') * 10 + s[4] - '0';
    v.push_back({h, m});
  }
  sort(v.begin(), v.end());
  int d, jwb = 0, sum = 0;
  for (int i = 1; i < n; ++i) {
    d = 0;
    d += 60 * (v[i].first - 1 - v[i - 1].first);
    if (v[i - 1].second <= v[i].second) {
      d += 60;
      d += v[i].second - v[i - 1].second;
    } else {
      d += v[i].second + 60 - v[i - 1].second;
    }
    jwb = max(jwb, d);
    sum += d;
  }
  jwb = max(jwb, 24 * 60 - sum);
  --jwb;
  if (jwb / 60 < 10)
    cout << '0' << jwb / 60;
  else
    cout << jwb / 60;
  cout << ':';
  if (jwb % 60 < 10)
    cout << '0' << jwb % 60;
  else
    cout << jwb % 60;
  return 0;
}
