void main() {
    string[] tmp = readln.split;
    uint n = tmp[0].to!uint;
    int m = tmp[1].to!int;
    long[] a = readln.split.to!(long[]);
    auto g = a.sort!"a > b".group.array;
    Tuple!(long, uint) t;
    foreach (i; 0 .. m) {
        tmp = readln.split;
        uint b = tmp[0].to!uint;
        long c = tmp[1].to!long;
        t[0] = c, t[1] = b;
        g ~= t;
    }
    g.sort!((t1, t2) => t1[0] > t2[0]);
    long ans;
    uint cnt;
    foreach (x; g) {
        if (cnt >= n) break;
        if (cnt + x[1] < n) {
            ans += x[0] * x[1].to!long;
            cnt += x[1];
        } else {
            ans += x[0] * (n - cnt).to!long;
            cnt = n;
        }
    }
    ans.writeln;
}

import std.stdio;
import std.string;
import std.array;
import std.conv;
import std.algorithm;
import std.range;
import std.typecons;