#include <bits/stdc++.h>
using namespace std;
signed main() {
  ios_base::sync_with_stdio(0);
  int n;
  cin >> n;
  vector<int> arr(n);
  for (int i = 0; i < n; i++) {
    string s;
    cin >> s;
    arr[i] = ((s[0] - 'a') * 10 + (s[1] - 'a')) * 60 + (s[3] - 'a') * 10 +
             (s[4] - 'a');
  }
  sort(arr.begin(), arr.end());
  int ans = 0;
  for (int i = 0; i < n - 1; i++) ans = max(ans, arr[i + 1] - arr[i]);
  ans = max(ans, arr[0] + 24 * 60 - arr[n - 1]);
  int h = (ans - 1) / 60;
  int m = (ans - 1) % 60;
  cout << (h < 10 ? "0" : "") << h << ":" << (m < 10 ? "0" : "") << m;
  return 0;
}
