#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii=pair<int, int>;
#define fastio ios_base::sync_with_stdio(false);cin.tie(0)
const int maxn=400055;
ll n,m,k;
pii p[maxn];
int F[maxn>>1];
int V[maxn>>1];
int A[maxn>>1];
ll chk(int ths) {
priority_queue<int> pq;
ll res=0;
for (int i=0; i<m+n; i++) {
auto[_,v]=p[i];
if (v>0) pq.push(v);
else if (v>=-ths){
if (pq.empty()) return 0;
res+=pq.top();
pq.pop();
}
}
return res;
}
int main() {
fastio;
cin >> n >> m;
for (int i=1; i<=n; i++) {
cin >> F[i] >> V[i];
p[i-1]={F[i],V[i]};
}
for (int i=1; i<=m; i++) {
cin >> A[i];
p[n+i-1]={A[i], -i};
}
sort(p,p+n+m, greater<pii>());
ll ans=0;
int lo=0, hi=m;
while (lo<hi) {
int mid=(lo+hi+1)>>1;
ll t=chk(mid);
if (t) lo=mid,ans=t;
else hi=mid-1;
}
cout << hi << ' ' << ans;
}