#include using namespace std; #define ll long long ll f[11][2005],ans; int n,m,i,j,k,a[100005],b[100005],c[1005],d[1005]; int main() { while(scanf("%d%d",&n,&m)!=EOF) { memset(f,127,sizeof(f)); for(i=1;i<=n;i++)scanf("%d%d",a+i,b+i); for(i=1;i<=m;i++)scanf("%d%d",c+i,d+i); for(i=ans=0;i<11;i++)for(f[i][0]=0,j=1;j<=m;j++)if(d[j]>i)for(k=d[j]-i;k<2001;k++)f[i][k]=min(f[i][k],f[i][k-d[j]+i]+c[j]); for(i=0;i<11;i++)for(j=2000;~j;j--)f[i][j]=min(f[i][j],f[i][j+1]); for(i=1;i<=n;i++)if(f[b[i]][a[i]]==f[0][2001]) { ans=-1; break; } else ans+=f[b[i]][a[i]]; cout<