#include <bits/stdc++.h>
using namespace std;
bool t[24 * 60];
int n;
int main() {
  memset(t, 0, sizeof(t));
  scanf("%d", &n);
  for (int i = 0; i < n; i++) {
    char s[10];
    scanf("%s", s);
    int hh = (s[0] - '0') * 10 + (s[1] - '0');
    int mm = (s[3] - '0') * 10 + (s[4] - '0');
    int ss = hh * 60 + mm;
    t[ss] = true;
  }
  int i = 0;
  while (i < 24 * 60 && t[i] == false) i++;
  int j = 24 * 60 - 1;
  while (j >= 0 && t[j] == false) j--;
  int ans = i + 24 * 60 - 1 - j;
  while (i < j) {
    while (i < j && t[i]) i++;
    int k = i;
    while (k < j && t[k] == false) k++;
    ans = max(ans, k - i);
    i = k;
  }
  int hh = ans / 60;
  int mm = ans % 60;
  printf("%d%d:%d%d\n", hh / 10, hh % 10, mm / 10, mm % 10);
  return (0);
}
