unittest
{
	assert( [ "10" ].parse.expand.solve == 5 );
	assert( [ "50" ].parse.expand.solve == 13 );
	assert( [ "10000000019" ].parse.expand.solve == 10000000018 );
}



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 );
	return tuple( n );
}

auto solve( long n )
{
	for( auto a = cast( long ) n ^^ 0.5L; 0 < a; a-- )
	{
		if( n % a == 0 ) return ( a + n / a ) - 2;
	}
	assert( false );
}
