/* imports all std modules {{{*/
import
  std.algorithm,
  std.array,
  std.ascii,
  std.base64,
  std.bigint,
  std.bitmanip,
  std.compiler,
  std.complex,
  std.concurrency,
  std.container,
  std.conv,
  std.csv,
  std.datetime,
  std.demangle,
  std.encoding,
  std.exception,
  std.file,
  std.format,
  std.functional,
  std.getopt,
  std.json,
  std.math,
  std.mathspecial,
  std.meta,
  std.mmfile,
  std.net.curl,
  std.net.isemail,
  std.numeric,
  std.parallelism,
  std.path,
  std.process,
  std.random,
  std.range,
  std.regex,
  std.signals,
  std.socket,
  std.stdint,
  std.stdio,
  std.string,
  std.system,
  std.traits,
  std.typecons,
  std.uni,
  std.uri,
  std.utf,
  std.uuid,
  std.variant,
  std.zip,
  std.zlib;
/*}}}*/

/+---test
3 2
5 1 4
2 3
1 5
---+/
/+---test
10 3
1 8 5 7 100 4 52 33 13 5
3 10
4 30
1 4
---+/
/+---test
3 2
100 100 100
3 99
3 99
---+/
/+---test
11 3
1 1 1 1 1 1 1 1 1 1 1
3 1000000000
4 1000000000
3 1000000000
---+/

void main(string[] args) {
  long N, M;
  readf(" %d %d ", &N, &M);

  auto A = readln.split.map!(to!long).array.sort!"a < b".array;

  auto op = new long[][](M, 2);
  foreach (ref o; op) {
    readf(" %d %d ", &o[0], &o[1]);
  }
  op = op.sort!"a[1] > b[1]".array;

  auto resa = appender!(long[]);
  resa.reserve(N);
A:foreach (o; op) foreach (i; 0..o[0]) {
    resa ~= o[1];
    if (resa.data.length >= N) break A;
  }

  long ans;
  foreach (a; zip(resa.data.chain([0].cycle), A)) {
    ans += max(a[0], a[1]);
  }
  ans.writeln;
}
