#include<iostream>
#include<algorithm>
#include<set>
#include<utility>
#include<queue>
using namespace std;
int main(){
priority_queue<pair<int, int>> que;
multiset<int> bag;
int N, K;
long long int ans = 0;
cin >> N >> K;
for(int i = 0; i<N; i++){
int tmp1, tmp2;
scanf("%d %d", &tmp1, &tmp2);
que.push(make_pair(tmp2, tmp1));
}
for(int i = 0; i<K; i++){
int tmp;
scanf("%d", &tmp);
bag.insert(tmp);
}
while(que.size() && bag.size()){
pair<int,int> tmp = que.top();
que.pop();
auto p = bag.lower_bound(tmp.second);
if(p != bag.end()){
ans+= tmp.first;
bag.erase(p);
}
}
cout<< ans<<endl;
}