#include #include #include using namespace std; long long n,m,a[100005],b[100005],v[100005],p[100005],f[12][100005]; long long ans; int main(){ while (~scanf("%I64d%I64d",&n,&m)){ for (int i=1;i<=n;i++) scanf("%I64d%I64d",&a[i],&b[i]); for (int i=1;i<=m;i++) scanf("%I64d%I64d",&v[i],&p[i]); for (int i=0;i<=10;i++){ for (int j=1;j<=1000;j++){ f[i][j]=10000000000000ll; for (int k=1;k<=m;k++) if (j-max(0ll,p[k]-i)>0) f[i][j]=min(f[i][j],f[i][j-max(0ll,p[k]-i)]+v[k]); else f[i][j]=min(f[i][j],v[k]); } } ans=0; for (int i=1;i<=n;i++){ if (f[b[i]][a[i]]==10000000000000ll){ans=-1;break;} ans+=f[b[i]][a[i]]; } printf("%I64d\n",ans); } }