unittest
{
	assert( [ "3 2", "5 1 4", "2 3", "1 5" ].parse.expand.solve == 14 );
	assert( [ "10 3", "1 8 5 7 100 4 52 33 13 5", "3 10", "4 30", "1 4" ].parse.expand.solve == 338 );
	assert( [ "3 2", "100 100 100", "3 99", "3 99" ].parse.expand.solve == 300 );
	assert( [ "11 3", "1 1 1 1 1 1 1 1 1 1 1", "3 1000000000", "4 1000000000", "3 1000000000" ].parse.expand.solve == 10000000001 );
}



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

auto solve( long[] as, long[][] bcs )
{
	as.sort();
	bcs.sort!( ( x, y ) => y[ 1 ] < x[ 1 ] )();
	
	// 一番小さいカードから順番に大きい整数に書き換えた結果を集計
	auto ans = 0L;
	foreach( a; as )
	{
		if( !bcs.empty && a < bcs.front[ 1 ] )
		{
			a = bcs.front[ 1 ];
			bcs.front[ 0 ]--;
			if( bcs.front[ 0 ] == 0 ) bcs.popFront();
		}
		ans += a;
	}
	return ans;
}
