#include <stdio.h>

int main(){
	int h1, m1, h2, m2, k;
	int one, two, final;
	
	scanf("%d %d %d %d %d", &h1, &m1, &h2, &m2, &k);
	
	one = h1 * 60 + m1;
	two = h2 * 60 + m2;
	final = one + two / k;
	
	printf("%d", final);
}