#include <bits/stdc++.h>
int cmpfunc(const void* a, const void* b) { return (*(int*)a - *(int*)b); }
int main() {
  int a[100] = {0};
  int n;
  scanf("%d\n", &n);
  for (int i = 0; i < n; i++) {
    char ch[5];
    scanf("%c%c%c%c%c\n", &ch[0], &ch[1], &ch[2], &ch[3], &ch[4]);
    a[i] = ((ch[0] - '0') * 10 + (ch[1] - '0')) * 60 + (ch[3] - '0') * 10 +
           ch[4] - '0';
  }
  qsort(a, n, sizeof(int), cmpfunc);
  int t = 24 * 60 - (a[n - 1] - a[0] + 1);
  for (int i = 1; i < n; i++) {
    if (a[i] - a[i - 1] - 1 > t) {
      t = a[i] - a[i - 1] - 1;
    }
  }
  char ch[5];
  ch[2] = ':';
  ch[0] = '0' + (t / 600);
  t %= 600;
  ch[1] = '0' + t / 60;
  t %= 60;
  ch[3] = '0' + t / 10;
  ch[4] = '0' + t % 10;
  printf("%c%c%c%c%c", ch[0], ch[1], ch[2], ch[3], ch[4]);
  return 0;
}
