#include <bits/stdc++.h>
int cmp(const void* a, const void* b) { return (*(int*)a - *(int*)b); }
int main() {
  int n, i;
  int h, m;
  scanf("%d", &n);
  int a[n];
  for (i = 0; i < n; i++) {
    scanf("%d:%d", &h, &m);
    a[i] = h * 60 + m;
  }
  qsort(a, n, sizeof(int), cmp);
  int ans = a[0] - a[n - 1] + 24 * 60 - 1;
  for (i = 1; i < n; i++) {
    int val = a[i] - a[i - 1] - 1;
    if (ans < val) {
      ans = val;
    }
  }
  h = ans / 60;
  if (h == 0)
    printf("00");
  else if (h < 10)
    printf("0%d", h);
  else
    printf("%d", h);
  m = ans % 60;
  if (m == 0)
    printf(":00");
  else if (m < 10)
    printf(":0%d", m);
  else
    printf(":%d", m);
}
