#include #include #include using namespace std; typedef long long ll; const int M=2010; int n,m,i,j,k,a[100010],b[100010],c[M],w[M],dp[M][11]; int main(){ while (scanf("%d%d",&n,&m)!=EOF){ for (i=1;i<=n;i++)scanf("%d%d",&a[i],&b[i]); for (i=1;i<=m;i++)scanf("%d%d",&w[i],&c[i]); for (i=0;i<=10;i++)dp[0][i]=0; for (i=1;i<=2000;i++) for (j=0;j<=10;j++)dp[i][j]=1<<30; for (i=1;i<=m;i++) for (j=0;j<=10&&j<=c[i];j++) for (k=0;k<=1000;k++) dp[k+c[i]-j][j]=min(dp[k+c[i]-j][j],dp[k][j]+w[i]); for (i=1999;i;i--) for (j=0;j<=10;j++) dp[i][j]=min(dp[i][j],dp[i+1][j]); ll ans=0; for (i=1;i<=n;i++){ if (dp[a[i]][b[i]]==1<<30){ans=-1;break;} ans+=dp[a[i]][b[i]]; } printf("%I64d\n",ans); } }