unittest
{
	assert( [ "41 2", "5 6" ].parse.expand.solve == 30 );
	assert( [ "10 2", "5 6" ].parse.expand.solve == -1 );
	assert( [ "11 2", "5 6" ].parse.expand.solve == 0 );
	assert( [ "314 15", "9 26 5 35 8 9 79 3 23 8 46 2 6 43 3" ].parse.expand.solve == 9 );
}



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

auto solve( long n, long[] as )
{
	auto t = as.sum;
	return ( t <= n ) ? n - t : -1;
}
