#include <stdio.h>

int main(void)
{
    int h1, m1, h2, m2, k, time_on, time_done, cnt = 0;

    scanf("%d %d %d %d %d", &h1, &m1, &h2, &m2, &k);
    time_done = 60*h2 + m2;
    time_on = 60*h1 + m1;

    while(time_on + k < time_done)
    {
        time_on+= k;
        cnt++;
    }

    printf("%d", cnt*k);

    return 0;
}
