#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  scanf("%d", &n);
  vector<int> a;
  for (int i = 0; i < n; i++) {
    int h, m;
    scanf("%d:%d", &h, &m);
    a.push_back(h * 60 + m);
  }
  sort(a.begin(), a.end());
  a.push_back(a[0]);
  int ans = 0;
  for (int i = 0; i < a.size() - 2; i++) {
    if (a[i + 1] - a[i] - 1 > ans) ans = a[i + 1] - a[i] - 1;
  }
  if (1439 - a[n - 1] + a[n] > ans) ans = 1439 - a[n - 1] + a[n];
  if (ans / 60 < 10) {
    cout << 0;
  }
  cout << ans / 60 << ':';
  if (ans % 60 < 10) {
    cout << 0;
  }
  cout << ans % 60;
  return 0;
}
