#include <bits/stdc++.h>
using namespace std;
const int N = (int)1e5 + 7;
const int inf = (int)1e9 + 7;
int tim[107];
int ans = 0;
int main() {
  int n;
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    int a, b;
    char c;
    scanf("%d%c%d", &a, &c, &b);
    tim[i] = a * 60 + b;
  }
  sort(tim + 1, tim + n + 1);
  for (int i = 2; i <= n; i++) {
    ans = max(tim[i] - tim[i - 1] - 1, ans);
  }
  ans = max(tim[1] - 1 + 1440 - tim[n], ans);
  int h = ans / 60;
  int m = ans % 60;
  if (h < 10) {
    printf("0");
  }
  printf("%d:", h);
  if (m < 10) {
    printf("0");
  }
  printf("%d", m);
}
