#include <bits/stdc++.h>
int cmpfunc(const void* a, const void* b) { return (*(int*)a - *(int*)b); }
int main() {
  int n = 0;
  scanf("%d\n", &n);
  int mins[101];
  int i = 0;
  for (i = 0; i < n; ++i) {
    int h, m;
    scanf("%d:%d", &h, &m);
    mins[i] = h * 60 + m;
  }
  qsort(mins, n, sizeof(int), cmpfunc);
  mins[n] = mins[0] + 24 * 60;
  int res = 0;
  for (i = 1; i <= n; ++i) {
    int nval = mins[i] - mins[i - 1] - 1;
    res = res > nval ? res : nval;
  }
  printf("%02d:%02d\n", res / 60, res % 60);
}
