import std.stdio;
import std.uni;
import std.string;
import core.stdc.stdio;
import std.array;
import std.algorithm;

int main(string[] argv)
{
	int n,k;
	scanf("%d", &n);
	int [] arr = new int[n];
	for(int i = 0; i<n; i++){
	    int h,m;
		scanf("%d:%d", &h,&m);
		h*=60;
		arr[i] = h+m;
	}
	arr.sort();
	int mx=0;
	for(int i=0;i<n-1;i++){
		int dif = arr[i+1] - arr[i] - 1;
		if(dif>mx)mx = dif;
	}
	int dif = 1440 - arr[n-1] + arr[0] - 1;
	if(dif>mx)mx=dif;
	if(n==1){
		printf("23:59\n");
	}
	if(n!=1){
	    if(mx/600==0){
	        printf("0");
	    }
		printf("%d:", mx/60);
		if((mx-mx/60*60)/10 == 0){
		    printf("0");
		}
		printf("%d\n",mx-mx/60*60);
	}
	return 0;
}