#include <algorithm>
#include <iostream>
#include <queue>
#include <vector>

#define let auto
#define fn auto
#define usize size_t

#define UMAX 0xfffffff

using namespace std;

fn fastio() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
}

struct Fire {
    usize f;
    usize v;
};

fn main() -> int {
    fastio();
    let _comp = [](Fire &a, const Fire &b) { return a.f < b.f; };
    usize n, m;
    cin >> n >> m;

    let fs = vector<Fire>(n);
    let bs = vector<usize>(m);

    for (usize i = 0; i < n; i++) {
        cin >> fs[i].f;
        cin >> fs[i].v;
    }

    sort(fs.begin(), fs.end(), _comp);

    for (usize i = 0; i < m; i++) {
        cin >> bs[i];
    }

    // 1pass
    usize last = UMAX;
    let vfx = vector<usize>();
    for (usize i = 0; i < m; i++) {
        let t = bs[i];

        Fire tf = {
                .f = t,
                .v = 0,
        };

        
        
    }

    if (last == UMAX) {
        last = m;
    }

    // 2pass
    sort(vfx.begin(), vfx.end());
    let heap = priority_queue<usize>();
    usize total_v = 0;
    while (vfx.size() > 0) {
        let key = *(vfx.end() - 1);
        vfx.pop_back();
        while (fs.size() > 0 && (fs.end() - 1)->f >= key) {
            heap.push((fs.end() - 1)->v);
            fs.pop_back();
        }

        total_v += heap.top();
        heap.pop();
    }

    cout << last << " " << total_v << endl;
}