unittest
{
	assert( [ "2 5", "4 9", "2 4" ].parse.expand.solve == 12 );
	assert( [ "4 30", "6 18", "2 5", "3 10", "7 9" ].parse.expand.solve == 130 );
	assert( [ "1 100000", "1000000000 100000" ].parse.expand.solve == 100000000000000 );
}



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[] );
	auto abs = new long[][]( nm[ 0 ], 2 );
	foreach( ref ab; abs )
	{
		input.popFront;
		ab = input.front.split.to!( long[] );
	}
	return tuple( nm[ 1 ], abs );
}

auto solve( long m, long[][] abs )
{
	abs.sort();
	
	auto ans = 0L;
	foreach( ab; abs )
	{
		ans += ab[ 0 ] * min( m, ab[ 1 ] );
		m -= ab[ 1 ];
		if( m <= 0 ) break;
	}
	
	return ans;
}
