unittest
{
	assert( [ "7 3", "3 2 2" ].parse.expand.solve == 0 );
	assert( [ "6 3", "1 4 1" ].parse.expand.solve == 1 );
	assert( [ "100 1", "100" ].parse.expand.solve == 99 );
}



import std.algorithm;
import std.conv;
import std.math;
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 kt = input.front.split.to!( long[] );
	input.popFront;
	auto as = input.front.split.to!( long[] );
	return tuple( kt[ 0 ], as );
}

auto solve( long k, long[] as )
{
	as.sort!( ( x, y ) => y < x );
	
	auto ans = 0L;
	auto a1 = as.front;
	as.popFront;
	foreach( a2; as )
	{
		a1 = ( a1 - a2 ).abs;
	}
	if( 0 < a1 ) ans += a1 - 1;
	return ans;
}
