#include #include #include #include #include #include #include #include #include using namespace std; inline void write(int a){ if(a>=10)write(a/10); putchar('0'+a%10); } inline void writeln(int a){ write(a); puts(""); } inline int read()//不管是正负数,都可以 { int x = 0; char ch = getchar(); bool positive = 1; for (; !isdigit(ch); ch = getchar()) if (ch == '-') positive = 0; for (; isdigit(ch); ch = getchar()) x = x * 10 + ch - '0'; return positive ? x : -x; } const int N=100005; int T,n,m,a[N],b[N],k[N],p[N],dp[15][2005],oo=1000000005; long long ans; int main(){ while(scanf("%d%d",&n,&m)==2){int flag=ans=0; for(int i=1;i<=n;i++){a[i]=read(); b[i]=read();} for(int i=1;i<=m;i++){k[i]=read(); p[i]=read();} for(int i=0;i<=10;i++){for(int j=0;j<=2000;j++)dp[i][j]=oo; dp[i][0]=0;} for(int i=0;i<=10;i++) for(int l=1;l<=m;l++)if(p[l]>i) for(int j=p[l]-i;j<=2000;j++){ dp[i][j]=min(dp[i][j],dp[i][j-p[l]+i]+k[l]); } for(int i=0;i<=10;i++){ for(int j=1999;j;j--){ dp[i][j]=min(dp[i][j],dp[i][j+1]); } } for(int i=1;i<=n;i++){ if(dp[b[i]][a[i]]>=oo){flag=1; puts("-1"); break;}ans+=dp[b[i]][a[i]]; } if(!flag) cout<