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

alias sread = () => readln.chomp();
long bignum = 1_000_000_007;
alias Pair = Tuple!(long, "numbers", long, "change");

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;
    }
}

void main()
{
    long n, m;
    scan(n, m);
    auto a = aryread.sort();
    auto bc = new Pair[](m);
    long b_sum;
    foreach (i; 0 .. m)
    {
        long b, c;
        scan(b, c);
        bc[i] = Pair(b, c);
        b_sum += b;
    }
    bc.sort!"a.change > b.change"();
    long j, corrent_b, corrent_sum;
    long cards_sum = a.sum, replace;
    long max_sum = cards_sum;
    foreach (i; 0 .. min(n, b_sum))
    {
        if (bc[j].numbers <= corrent_b)
        {
            j++;
            corrent_b = 0;
        }

        corrent_sum += bc[j].change;
        corrent_b++;
        replace += a[i];
        max_sum = max(max_sum, cards_sum - replace + corrent_sum);
    }
    max_sum.writeln();
}
