#!/bin/bash

read h1 m1 h2 m2 k

h=`expr $h2 - $h1`
if [ $m2 -ge $m1 ]; then
        m=`expr $m2 - $m1`
else
        h=`expr $h - 1`
        m=`expr $m2 - $m1 + 60`
fi

ANS=`expr $h \* 60 + $m - $k`
echo "$ANS"