#include <bits/stdc++.h>
int n, h, m, cnt, ans, x[3600];
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) scanf("%d:%d", &h, &m), x[h * 60 + m] = 1;
  while (!x[ans]) ans++;
  for (int i = 1439; i >= 0; i--)
    if (x[i])
      break;
    else
      ans++;
  for (int i = 0; i < 1440; i++)
    if (x[i])
      ans = ans > cnt ? ans : cnt, cnt = 0;
    else
      cnt++;
  return printf("%d%d:%d%d\n", ans / 600, (ans / 60) % 10, (ans % 60) / 10,
                ans % 10),
         0;
}
