module main;
import core.stdc.stdio;
import std.algorithm;

int main(string[] argv)
{
    int n, ans = 0;
    scanf("%d", &n);
    int[] t = new int[n];
    for (int i = 0; i < n; ++i) {
        int h, m;
        scanf("%d:%d", &h, &m);
        t[i] = 60*h+m;
    }
    if (n == 1) {
        puts("23:59");
        return 0;
    }
    t.sort();
    
    for (int i = 1; i < n; ++i) {
        int v = t[i]-t[i-1]-1;
        if (v > ans) ans = v;
    }
    int tmp = 60*24+t[0]-t[n-1]-1;
    if (tmp > ans) ans = tmp;
    printf("%02d:%02d\n", ans/60, ans%60);
    
    return 0;
}