import std.algorithm;
import std.concurrency;
import std.container;
import std.conv;
import std.functional;
import std.math;
import std.meta;
import std.random;
import std.range;
import std.stdio;
import std.string;
import std.traits;
import std.typecons;


auto solve(long N, long M, long[] A, long[] B, long[] C) {
    long[long] counter;
    foreach (a; A)
        counter[a]++;
    foreach (b, c; zip(B, C))
        counter[c] += b;
    
    long left = N;
    long ans;
    foreach (k; counter.keys.sort!"a > b") {
        auto consumption = min(left, counter[k]);
        ans += k * consumption;
        left -= consumption;
        if (left <= 0)
            break;
    }

    return ans;
}


void main() {
    auto input = stdin.byLine.map!split.joiner;

    long N;
    N = input.front.to!long;
    input.popFront;

    long M;
    M = input.front.to!long;
    input.popFront;

    long[] A = new long[](cast(size_t) (N));
    foreach (i; 0 .. cast(size_t) (N)) {
        A[i] = input.front.to!long;
        input.popFront;
    }

    long[] B = new long[](cast(size_t) (M));
    long[] C = new long[](cast(size_t) (M));
    foreach (i; 0 .. cast(size_t) (M)) {
        B[i] = input.front.to!long;
        input.popFront;
        C[i] = input.front.to!long;
        input.popFront;
    }

    static if (is(ReturnType!solve == void))
        solve(N, M, A, B, C);
    else
        solve(N, M, A, B, C).writeln;
}
