#include #include #include #include #include #include #include using namespace std; const int N=1E5+5; const long long inf=1E15; int n,m,a[N],b[N],k[N],p[N]; long long ans,dp[1005][15],w; int main() { //freopen("1.in","r",stdin); freopen("1.out","w",stdout); while (cin>>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]); for (int j=0;j<=10;j++) for (int i=1;i<=1000;i++) { dp[i][j]=inf; for (int r=1;r<=m;r++) if (p[r]>j) { if (p[r]-j>=i) w=0; else w=dp[i-(p[r]-j)][j]; dp[i][j]=min(dp[i][j],w+k[r]); } } ans=0; for (int i=1;i<=n&&ans<=inf;i++) ans+=dp[a[i]][b[i]]; if (ans>=inf) printf("-1\n"); else printf("%I64d\n",ans); } }