#include using namespace std; const long long INF = 1e17+10;; int n,m; int a[100000+10]; int b[100000+10]; long long dp[20][2001]; int k[1005]; int p[1005]; int solve(int kk){ dp[kk][0]=0; for(int i=1;i<=m;i++){ if(p[i]<=kk) continue; for(int j = p[i]-kk;j<=2000;j++){ dp[kk][j] = min(dp[kk][j-p[i]+kk]+(long long)k[i],dp[kk][j]); } } for(int i=1999;i>=1;i--) dp[kk][i]=min(dp[kk][i],dp[kk][i+1]); return 0; } int main(){ while(~scanf("%d%d",&n,&m)){ for(int i=1;i<=n;i++) scanf("%d%d",&a[i],&b[i]); for(int i=1;i<=m;i++) scanf("%d%d",&k[i],&p[i]); memset(dp,INF,sizeof(dp)); for(int i=0;i<=10;i++){ solve(i); } long long ans = 0; bool flag = true; for(int i=1;i<=n;i++){ long long minn = INF; for(int j=b[i];j<=10;j++){ minn = min(minn,dp[j][a[i]]); } if(minn==INF){ flag=false; break; } // printf("%d\n",minn); ans+=minn; } if(flag) printf("%lld\n",ans); else printf("-1\n"); } return 0; }