#include <stdio.h>

int main() {

	int h1, m1, h2, m2, k;
	scanf("%d %d %d %d %d", &h1, &m1, &h2, &m2, &k);
	
	h1*=60;
	h2*=60;
	
	int waktu=h2+m2-h1-m1;
	int output= waktu/k-1;
	output*=k;
	
	printf("%d\n", output);
	


    return 0;
}
