unittest
{
	assert( [ "4", "1 2 2 1" ].parse.expand.solve == 2 );
	assert( [ "5", "3 1 2 3 1" ].parse.expand.solve == 5 );
	assert( [ "8", "4 23 75 0 23 96 50 100" ].parse.expand.solve == 221 );
}



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 n = input.front.to!( long );
	input.popFront;
	auto hs = input.front.split.to!( long[] );
	return tuple( hs );
}

auto solve( long[] hs )
{
	auto ans = 0L;
	
	for( auto k = 0; k < hs.length; k++ )
	{
		while( 0 < hs[ k ] )
		{
			for( auto i = k; i < hs.length; i++ )
			{
				if( hs[ i ] <= 0 ) break;
				hs[ i ]--;
			}
			ans++;
		}
	}
	
	return ans;
}
