#include <bits/stdc++.h>
const int LIM = 1e5;
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int n;
  cin >> n;
  string s;
  vector<int> times(n, 0);
  for (int i = 0; i < n; i++) {
    cin >> s;
    int t = (s[0] - '0') * 10 + (s[1] - '0');
    t *= 60;
    t += (s[3] - '0') * 10 + (s[4] - '0');
    times[i] = t;
  }
  sort(times.begin(), times.end());
  int maxt = times[0] + (1440 - times[n - 1] - 1);
  for (int i = 1; i < n; i++) maxt = max(maxt, times[i] - times[i - 1] - 1);
  if (maxt / 60 < 10) cout << '0';
  cout << maxt / 60 << ':';
  if (maxt % 60 < 10) cout << '0';
  cout << maxt % 60 << '\n';
  return 0;
}
