unittest
{
	assert( [ "2 5 4" ].parse.expand.solve == 2 );
	assert( [ "2 6 3" ].parse.expand.solve == 5 );
	assert( [ "31 41 5" ].parse.expand.solve == 23 );
}



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

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

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

auto solve( long[] abc )
{
	abc = abc.sort().array;
	
	auto i = 0;
	while( abc[ 0 ] != abc[ 1 ] || abc[ 0 ] != abc[ 2 ] )
	{
		switch( abc[ 1 ] - abc[ 0 ] )
		{
			case 0:
				abc[ 0 ]++;
				abc[ 1 ]++;
				break;
			
			case 1:
				abc[ 0 ]++;
				abc[ 2 ]++;
				break;
			
			default:
				abc[ 0 ] += 2;
				break;
		}
		
		i++;
	}

	return i;
}
