unittest
{
	assert( [ "10 0 15 0 30" ].parse.expand.solve == 270 );
	assert( [ "10 0 12 0 120" ].parse.expand.solve == 0 );
}



import std.conv;
import std.range;
import std.stdio;
import std.typecons;

void main()
{
	stdin.byLineCopy.parse.expand.solve.writeln;
}

auto parse( Range )( Range input )
if( isInputRange!Range && is( ElementType!Range == string ) )
{
	auto hmhmk = input.front.split.to!( long[] );
	return tuple( hmhmk[ 0 .. 2 ], hmhmk[ 2 .. 4 ], hmhmk[ 4 ] );
}

auto solve( long[] hm1, long[] hm2, long k )
{
	auto a = hm1[ 0 ] * 60 + hm1[ 1 ];
	auto b = hm2[ 0 ] * 60 + hm2[ 1 ];
	return b - a - k;
}
