import core.bitop, std.algorithm, std.ascii, std.bigint, std.conv, std.math,
    std.functional, std.numeric, std.range, std.stdio, std.string, std.random,
    std.typecons, std.container;

// dfmt off
T lread(T = long)(){return readln.chomp.to!T();}
T[] aryread(T = long)(){return readln.split.to!(T[])();}
void scan(TList...)(ref TList Args){auto line = readln.split();
foreach (i, T; TList){T val = line[i].to!(T);Args[i] = val;}}
alias sread = () => readln.chomp();enum MOD = 10 ^^ 9 + 7;
// dfmt on

void main()
{
    long n, m;
    scan(n, m);
    auto A = aryread();
    long[] B, C;
    foreach (_; 0 .. m)
    {
        long b, c;
        scan(b, c);
        B ~= b;
        C ~= c;
    }

    A.sort();
    zip(C, B).sort!"b<a"();
    // A.writeln();
    // B.writeln();
    // C.writeln();
    size_t i = 0;
    long ans = A.sum();
    outer: foreach (j; 0 .. m)
    {
        foreach (k; 0 .. B[j])
        {
            if (A[i] < C[j])
            {
                // writefln("%d -> %d", A[i], C[j]);
                ans -= A[i];
                ans += C[j];
                i++;
            }
            else
            {
                break outer;
            }
        }
    }
    writeln(ans);
}
