#include <bits/stdc++.h>
int main() {
  int t, n, c, ans, x, y, a[5000];
  char ch;
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    scanf("%d%c%d", &x, &ch, &y);
    a[i] = x * 60 + y;
  }
  for (int i = 1; i <= n; i++)
    for (int j = 2; j <= n; j++)
      if (a[j] < a[j - 1]) {
        c = a[j];
        a[j] = a[j - 1];
        a[j - 1] = c;
      }
  a[n + 1] = a[1] + 1440;
  ans = 0;
  for (int i = 2; i <= n + 1; i++) {
    if (a[i] - a[i - 1] > ans + 1) ans = a[i] - a[i - 1] - 1;
  }
  printf("%02d:%02d", ans / 60, ans % 60);
}
