import std.stdio;
import std.algorithm;
import std.math;
import std.conv;
import std.string;
import std.range;

auto readNum(T)(){
  return readln.chomp.to!T;
}

auto readNums(T)(){
  return readln.chomp.split.to!(T[]);
}

void main(){
  auto nm = readNums!int;
  auto a = readNums!long;

  long[] b;

  foreach(i; 0 .. nm[1]){
    auto bc = readNums!long;
    foreach(j; 0 .. bc[0]){
      b ~= bc[1];
    }
  }

  a = sort!("a < b")(a).array;
  b = sort!("a > b")(b).array;
  long r;

  foreach(i; 0 .. min(a.length, b.length)){
    if(a[i] < b[i]){
      r += -1 * a[i] + b[i];
    }
  }

  writeln(a.sum + r);
}
