#include <stdio.h>

int main(){
    
    int H1, M1, H2, M2, K;
    int output;
    scanf("%d %d %d %d %d", H1, M1, H2, M2, K);
    output = (H1*60) + M1 + (H2*60) + M2;
    if(K == output){
    	printf("0");
	}
    printf("%d", output);
    return 0;
}