#include <bits/stdc++.h>
int ts[110];
int max(int a, int b) { return a > b ? a : b; }
int main() {
  int n;
  scanf("%d", &n);
  for (int i = 0; i < n; i++) {
    int hh, mm;
    scanf("%02d:%02d", &hh, &mm);
    ts[i] = hh * 60 + mm;
  }
  for (int i = 0; i < n; i++) {
    for (int j = i + 1; j < n; j++) {
      if (ts[i] > ts[j]) {
        int tmp = ts[i];
        ts[i] = ts[j];
        ts[j] = tmp;
      }
    }
  }
  int ans = 0;
  for (int i = 1; i < n; i++) ans = max(ans, ts[i] - ts[i - 1] - 1);
  ans = max(ans, ts[0] + 24 * 60 - ts[n - 1] - 1);
  int hh = ans / 60;
  int mm = ans % 60;
  printf("%02d:%02d\n", hh, mm);
  return 0;
}
