#pragma comment(linker,"/STACK:100000000000,100000000000")
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <string>
#include <cstring>
#include <vector>
#include <cmath>
#include <map>
#include <stack>
#include <set>
#include <iomanip>
#include <queue>
#include <map>
#include <functional>
#include <memory.h>
#include <list>
#include <sstream>
#include <ctime>
#include <climits>
#include <bitset>
#include <list>
#include <cassert>
#include <complex>
using namespace std;
/* Constants begin */
const long long inf = 1e18+7;
const long long mod = 1e9+7;
const double eps = 1e-12;
const double PI = 2*acos(0.0);
const double E = 2.71828;
/* Constants end */
/* Defines begin */
#define pb push_back
#define mp make_pair
#define ll long long
#define double long double
#define F first
#define S second
#define all(a) (a).begin(),(a).end()
#define forn(i,n) for (ll (i)=0;(i)<(ll)(n);(i)++)
#define random (rand()<<16|rand())
#define sqr(x) (x)*(x)
#define base complex<double>
/* Defines end */
vector<pair<ll,ll> > q;
multiset<ll> S;
int main(void) {
#ifndef ONLINE_JUDGE
freopen("input.txt","rt",stdin);
freopen("output.txt","wt",stdout);
#endif
int n, k; scanf("%d%d",&n,&k);
q.resize(n);
ll res = 0;
forn(i,n){
int a, b; scanf("%d%d",&a,&b);
q[i] = mp(b,a);
res += b;
}
sort(all(q));
reverse(all(q));
forn(i,k){
int a; scanf("%d",&a);
S.insert(a);
}
forn(i,q.size()){
set<ll> :: iterator it = S.lower_bound(q[i].S);
if(it == S.end()){
res -= q[i].F;
} else {
S.erase(it);
}
}
cout << res << endl;
return 0;
}
I3ByYWdtYSBjb21tZW50KGxpbmtlciwiL1NUQUNLOjEwMDAwMDAwMDAwMCwxMDAwMDAwMDAwMDAiKQoKI2luY2x1ZGUgPGlvc3RyZWFtPgojaW5jbHVkZSA8Y3N0ZGlvPgojaW5jbHVkZSA8Y3N0ZGxpYj4KI2luY2x1ZGUgPGFsZ29yaXRobT4KI2luY2x1ZGUgPHN0cmluZz4KI2luY2x1ZGUgPGNzdHJpbmc+CiNpbmNsdWRlIDx2ZWN0b3I+CiNpbmN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