#include <bits/stdc++.h>
int n, a[200], ans = 0, h, m;
char t;
int main() {
  scanf("%d", &n);
  for (int i = 0; i < n; i++) {
    scanf("%d%c%d", &h, &t, &m);
    a[i] = h * 60 + m;
  }
  for (int i = 0; i < n; i++) {
    for (int j = i + 1; j < n; j++) {
      if (a[i] > a[j]) {
        int tmp = a[i];
        a[i] = a[j];
        a[j] = tmp;
      }
    }
  }
  a[n] = a[0] + 1440;
  for (int i = 0; i < n; i++) {
    int tans = a[i + 1] - a[i];
    if (tans > ans) {
      ans = tans;
    }
  }
  ans--;
  h = ans / 60;
  m = ans % 60;
  if (h < 10) {
    printf("%d", 0);
  }
  printf("%d", h);
  printf("%c", ':');
  if (m < 10) {
    printf("%d", 0);
  }
  printf("%d", m);
  return 0;
}
