#include <iostream>
#include <vector>
#include <algorithm>
#include <set>
#define MP make_pair
#define F first
#define S second
int N, K;
using namespace std;
multisetset<long long> bags;
set<long long>::iterator it;
vector<pair<int, int> > jw;
int tr(int m){
it=bags.lower_bound(m);
if (it==bags.end()) return 0;
bags.erase(it);
return 1;
}
int main(){
cin >> N >> K;
for (int i=0; i<N; ++i){
int M, V;
cin >> M >> V;
jw.push_back(MP(-V, M));
} sort(jw.begin(), jw.end());
for (int i=0; i<K; ++i){
long long C;
cin >> C;
bags.insert(C);
}
long long ans=0;
for (int i=0; i<jw.size(); ++i){
ans-=tr(jw[i].S)*jw[i].F;
}
cout << ans << "\n";
}