#include #include #include #include #include #include #include #include #include #include using namespace std; typedef long long ll; #define inf 100000000000000000 #define mod 1000000007 #define maxn 1000010 #define lowbit(x) (x&-x) #define eps 1e-10 ll a[maxn],b[maxn],dp[2006][15],k[maxn],p[maxn]; int main(void) { ll n,m,i,j,ans,m1,m2,maxs; while(scanf("%lld%lld",&n,&m)!=EOF) { ans=0;m1=m2=0;maxs=0; for(i=1;i<=n;i++) { scanf("%lld%lld",&a[i],&b[i]); m1=max(m1,b[i]); maxs=max(maxs,a[i]); } for(i=1;i<=m;i++) { scanf("%lld%lld",&k[i],&p[i]); m2=max(m2,p[i]); } if(m1>=m2) { printf("-1\n"); continue; } for(i=1;i<=2005;i++) for(j=0;j<=10;j++) dp[i][j]=inf; for(i=0;i<=10;i++) { dp[0][i]=0; for(j=1;j<=m;j++) { ll t=p[j]-i; if(t<=0) continue; for(ll h=t;h<=2003;h++) dp[h][i]=min(dp[h-t][i]+k[j],dp[h][i]); } for(j=2002;j>=0;j--) dp[j][i]=min(dp[j][i],dp[j+1][i]); } for(i=1;i<=n;i++) ans+=dp[a[i]][b[i]]; printf("%lld\n",ans); } return 0; }