#include <bits/stdc++.h>
#define ll long long
#define BUF 1e5
constexpr int INF = (1LL << 31) - 1;
constexpr ll mod = 1e9 + 7;
using namespace std;
ll A, B, C, D, G, H, N, M, L, K, P, Q, R, W, X, Y, Z;
string S, T;
ll ans = 0;

template <typename T>
class LazySegmentTreeSUM {
public:
    vector<T> node;
    vector<T> lazy;
    int size;
    int n;
    LazySegmentTreeSUM() {}
    LazySegmentTreeSUM(vector<T> in) {
        int in_sz = in.size();
        n = 1;
        while (n < in_sz) {
            n *= 2;
        }
        size = n * 2 - 1;
        node.resize(size, 0);
        lazy.resize(size, -1);
        for (int i = 0; i < in_sz; i++) {
            node[n - 1 + i] = in[i];
        }
        init_dfs(0);
    }

    T init_dfs(int now) {
        if (2 * now + 1 >= size)
            return node[now];
        node[now] = init_dfs(2 * now + 1) + init_dfs(2 * now + 2);
        return node[now];
    }
    void eval(int now, int l, int r) {
        if (lazy[now] >= 0) {
            node[now] = (r - l) * lazy[now];
            if (r - l > 1) {
                lazy[2 * now + 1] = lazy[now];
                lazy[2 * now + 2] = lazy[now];
            }
            lazy[now] = -1;
        }
    }

    void update(int a, int b, T val) {
        _update(a, b, val, 0, 0, n);
    }

    void _update(int a, int b, T val, int now, int l, int r) {
        eval(now, l, r);
        if (r <= a || b <= l)
            return;
        if (a <= l && r <= b) {
            lazy[now] = val;
            eval(now, l, r);
            return;
        }
        _update(a, b, val, 2 * now + 1, l, (l + r) / 2);
        _update(a, b, val, 2 * now + 2, (l + r) / 2, r);
        node[now] = node[2 * now + 1] + node[2 * now + 2];
    }

    T query(int a, int b) {
        return _query(a, b, 0, 0, n);
    }

    T _query(int a, int b, int now, int l, int r) {
        if (r <= a || b <= l)
            return 0;
        eval(now, l, r);
        if (a <= l && r <= b)
            return node[now];
        T val_l = _query(a, b, 2 * now + 1, l, (l + r) / 2);
        T val_r = _query(a, b, 2 * now + 2, (l + r) / 2, r);
        return val_l + val_r;
    }
};
template <typename T>
class LazySegmentTreeRMQ {
public:
    vector<T> node;
    vector<bool> lazyflag;
    vector<T> lazy;
    int size;
    int n;
    LazySegmentTreeRMQ() {}
    LazySegmentTreeRMQ(vector<T> in) {
        int in_sz = in.size();
        n = 1;
        while (n < in_sz) {
            n *= 2;
        }
        size = n * 2 - 1;
        node.resize(size, INF);
        lazy.resize(size, INF);
        lazyflag.resize(size, 0);
        for (int i = 0; i < in_sz; i++) {
            node[n - 1 + i] = in[i];
        }
        init_dfs(0);
    }

    T init_dfs(int now) {
        if (2 * now + 1 >= size)
            return node[now];
        node[now] = init_dfs(2 * now + 1) + init_dfs(2 * now + 2);
        return node[now];
    }
    void eval(int now, int l, int r) {
        if (lazyflag[now] == 1) {
            node[now] = min(node[now], lazy[now]);
            if (r - l > 1) {
                lazy[2 * now + 1] = min(lazy[2 * now + 1], lazy[now]);
                lazyflag[2 * now + 1] = 1;
                lazy[2 * now + 2] = min(lazy[2 * now + 2], lazy[now]);
                lazyflag[2 * now + 2] = 1;
            }
            lazyflag[now] = 0;
            lazy[now] = INF;
        }
    }

    void update(int a, int b, T val) {
        _update(a, b, val, 0, 0, n);
    }

    void _update(int a, int b, T val, int now, int l, int r) {
        eval(now, l, r);
        if (r <= a || b <= l)
            return;
        if (a <= l && r <= b) {
            lazy[now] = val;
            lazyflag[now] = 1;
            eval(now, l, r);
            return;
        }
        _update(a, b, val, 2 * now + 1, l, (l + r) / 2);
        _update(a, b, val, 2 * now + 2, (l + r) / 2, r);
        node[now] = min(node[2 * now + 1], node[2 * now + 2]);
    }

    T query(int a, int b) {
        return _query(a, b, 0, 0, n);
    }

    T _query(int a, int b, int now, int l, int r) {
        if (r <= a || b <= l)
            return INF;
        eval(now, l, r);
        if (a <= l && r <= b)
            return node[now];
        T val_l = _query(a, b, 2 * now + 1, l, (l + r) / 2);
        T val_r = _query(a, b, 2 * now + 2, (l + r) / 2, r);
        return min(val_l, val_r);
    }
};

signed main() {
    cin >> N >> M;
    vector<ll> a(N);
    vector<pair<int, int>> cb(M);
    for (int i = 0; i < N; i++) {
        cin >> a[i];
    }
    for (int i = 0; i < M; i++) {
        cin >> cb[i].second >> cb[i].first;
    }
    sort(a.begin(), a.end());
    sort(cb.rbegin(), cb.rend());
    LazySegmentTreeSUM<ll> lst(a);
    auto prev = a.begin();
    for (int i = 0; i < M; i++) {
        int b = cb[i].second;
        int c = cb[i].first;
        auto it = lower_bound(prev, a.end(), c);
        if (it - prev > b) {
            int ind = prev - a.begin();
            lst.update(ind, ind + b, c);
            prev += b;
        } else {
            lst.update(prev - a.begin(), it - a.begin(), c);
            break;
        }
    }
    cout << lst.query(0, N) << endl;
}


Measured memory_bytes: 6656