#include <bits/stdc++.h>
using namespace std;
#define int long long
#define nl '\n'
#define fromst(i, start, j) for (int i = start; i <= j; i++)
#define from(i, j) for (int i = 0; i < j; i++)
const int maxn = 1e4 + 1;
int n, m;
vector<int> a(1e4);
struct light {
int p, r;
};
vector<light> b(11);
void solve() {
vector<int> dp(1000001, 1e17), idx(1000001);
set<int> pos;
dp[1] = dp[0] = 0;
fromst(i, 1, n) {
if (dp[i - 1] == 1e17) continue;
from(j, m) {
auto nd = upper_bound(a.begin() + i, a.begin() + n + 1, a[i] + b[j].r) - a.begin() - 1;
if (nd < i) continue;
auto st = upper_bound(a.begin() + nd, a.begin() + n + 1, a[nd] + b[j].r) - a.begin() - 1;
if (dp[st] > dp[i - 1] + b[j].p) {
dp[st] = dp[i - 1] + b[j].p;
pos.insert(st);
idx[st] = j + 1;
}
}
}
cout << dp[n] << ' ' << pos.size() << nl;
}
signed main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
cin >> n >> m;
from(i, m) cin >> b[i].p >> b[i].r;
fromst(i, 1, n) cin >> a[i];
sort(a.begin(), a.begin() + n + 1);
solve();
return 0;
}
I2luY2x1ZGUgPGJpdHMvc3RkYysrLmg+CnVzaW5nIG5hbWVzcGFjZSBzdGQ7CgojZGVmaW5lIGludCBsb25nIGxvbmcKI2RlZmluZSBubCAnXG4nCiNkZWZpbmUgZnJvbXN0KGksIHN0YXJ0LCBqKSBmb3IgKGludCBpID0gc3RhcnQ7IGkgPD0gajsgaSsrKQojZGVmaW5lIGZyb20oaSwgaikgZm9yIChpbnQgaSA9IDA7IGkgPCBqOyBpKyspCgpjb25zdCBpbnQgbWF4biA9IDFlNCArIDE7CgppbnQgbiwgbTsKdmVjdG9yPGludD4gYSgxZTQpOwoKc3RydWN0IGxpZ2h0IHsKICAgIGludCBwLCByOwp9OwoKdmVjdG9yPGxpZ2h0PiBiKDExKTsKCnZvaWQgc29sdmUoKSB7CiAgICB2ZWN0b3I8aW50PiBkcCgxMDAwMDAxLCAxZTE3KSwgaWR4KDEwMDAwMDEpOwogICAgc2V0PGludD4gcG9zOwogICAgZHBbMV0gPSBkcFswXSA9IDA7CgogICAgZnJvbXN0KGksIDEsIG4pIHsKICAgICAgICBpZiAoZHBbaSAtIDFdID09IDFlMTcpIGNvbnRpbnVlOwogICAgICAgIAogICAgICAgIGZyb20oaiwgbSkgewogICAgICAgICAgICBhdXRvIG5kID0gdXBwZXJfYm91bmQoYS5iZWdpbigpICsgaSwgYS5iZWdpbigpICsgbiArIDEsIGFbaV0gKyBiW2pdLnIpIC0gYS5iZWdpbigpIC0gMTsKICAgICAgICAgICAgaWYgKG5kIDwgaSkgY29udGludWU7CgogICAgICAgICAgICBhdXRvIHN0ID0gdXBwZXJfYm91bmQoYS5iZWdpbigpICsgbmQsIGEuYmVnaW4oKSArIG4gKyAxLCBhW25kXSArIGJbal0ucikgLSBhLmJlZ2luKCkgLSAxOwoKICAgICAgICAgICAgaWYgKGRwW3N0XSA+IGRwW2kgLSAxXSArIGJbal0ucCkgewogICAgICAgICAgICAgICAgZHBbc3RdID0gZHBbaSAtIDFdICsgYltqXS5wOwogICAgICAgICAgICAgICAgcG9zLmluc2VydChzdCk7CiAgICAgICAgICAgICAgICBpZHhbc3RdID0gaiArIDE7CiAgICAgICAgICAgIH0KICAgICAgICB9CiAgICB9CiAgICAKICAgIGNvdXQgPDwgZHBbbl0gPDwgJyAnIDw8IHBvcy5zaXplKCkgPDwgbmw7Cn0KCnNpZ25lZCBtYWluKCkgewogICAgaW9zX2Jhc2U6OnN5bmNfd2l0aF9zdGRpbyhmYWxzZSk7CiAgICBjaW4udGllKE5VTEwpOwogICAgY291dC50aWUoTlVMTCk7CgogICAgY2luID4+IG4gPj4gbTsKICAgIGZyb20oaSwgbSkgY2luID4+IGJbaV0ucCA+PiBiW2ldLnI7CiAgICBmcm9tc3QoaSwgMSwgbikgY2luID4+IGFbaV07CgogICAgc29ydChhLmJlZ2luKCksIGEuYmVnaW4oKSArIG4gKyAxKTsKICAgIHNvbHZlKCk7CgogICAgcmV0dXJuIDA7Cn0K