#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <queue>
using namespace std;
struct object
{
int w,v;
}A[300005];
int bag[300005];
bool cmp1(struct object a,struct object b)
{
return a.w<b.w;
}
class cmp2
{
public:
bool operator()(struct object a,struct object b)
{
return a.v<b.v;
}
};
int main()
{
int n,m;
int i,j;
priority_queue<struct object,vector<struct object>,cmp2> Q;
scanf("%d%d",&n,&m);
for (i=0;i<n;i++)
scanf("%d%d",&A[i].w,&A[i].v);
for (i=0;i<m;i++)
scanf("%d",&bag[i]);
sort(A,A+n,cmp1);
sort(bag,bag+m);
int Apos=0;
long long ans=0;
for (i=0;i<m;i++)
{
while (Apos<n && A[Apos].w<=bag[i])
{
Q.push(A[Apos]);
Apos++;
}
if (!Q.empty())
{
ans+=Q.top().v;
Q.pop();
}
}
printf("%lld\n",ans);
}