#include <stdio.h>
#include <ctype.h>
#include <string.h>
int main() {
    char s[1000];
    fgets(s, 500, stdin);
    int brojac = 0;
    int najdolg_termin = 0;
    int h, sec;
    for(int i = 0; i < strlen(s); i++) {
        if(s[i] == ':') {
            if(isdigit(s[i - 1]) && isdigit(s[i - 2]) && isdigit(s[i + 1]) && isdigit(s[i + 2])) {
                brojac++;
                int hours = (s[i - 2] - '0') * 10 + (s[i - 1] - '0');
                int minutes = (s[i + 1] - '0') * 10 + (s[i + 2] - '0');

                if(najdolg_termin < hours * 60 + minutes) {
                    najdolg_termin = hours * 60 + minutes;
                    h = hours;
                    sec = minutes;
                }

            }
        }
    }
    printf("Vo tekstot ima navedneo %d vremenski termini. Najdocniot termin e %d:%d\n", brojac, h, sec);
   
    return 0;
}


/*
Predavanjata po PiA pochnuvaat vo 08:00 chasot, a auditoriskite vezhbi pochnuvaat vo 12:00 chasot. Za laboratoriski vezhbi na raspolaganje ima tri termini: prviot od 14:00 vo 322A, vtoriot od 15:30 vo 322A i tretiot od 18:30 vo 322A
*/