import std.stdio;

void main(string[] args) {
   int n;
   int[1440] time;
   scanf("%d", &n);
   for ( int i = 0; i < 1440; i++ ) { 
      time[ i ] = 0; 
   }
   int h, m;
   for ( int i = 0; i < n; i++ ) { 
      scanf("%d:%d", &h, &m);
      time[h*60+m] = 1;
   }
   int mm=0;
   int cur=0;
   int cur1=0;
   int t = 0;
   for ( int i = 0; i < 1440; i++){
      if (time[i] == 0){
        cur = cur + 1;
      }
      else {
        if (t == 0){
            cur1 = cur;
            cur = 0;
            t = 1;
        }
        if (cur > mm){
            mm = cur;
        }
        cur = 0;
      }
   }
   if (cur+cur1 > mm){
        mm = cur+cur1;
    }
   writeln(mm/60/10,mm/60%10,":",mm%60/10,mm%60%10);
}