#include #include #include #include #include #include #include #include #include #include #include #include using namespace std; typedef long long LL; const int maxn = 1e5+2333; const int MOD = 1e9+7; const LL inf = 1e18+7; const double eps= 1e-8; const double pi = acos(-1.0); int n,m,tot,cnt,ans,tmp; inline LL read() { int c=0,f=1; char ch=getchar(); while(ch<'0'||ch>'9') { if(ch=='-')f=-1; ch=getchar(); } while(ch>='0'&&ch<='9') { c=c*10+ch-'0'; ch=getchar(); } return c*f; } struct node1 { LL a,b,sum; } king[maxn]; struct node2 { LL k,p; } dd[maxn]; LL dp[2005][15];///dp[i][j]为花费 i为生命值 j为防御值 int main() { // freopen("in.txt","r",stdin); while(~scanf("%d %d",&n,&m)) { int monster_sum=0; for(int i=1; i<=n; ++i) { king[i].a=read(); king[i].b=read(); } for(int i=1; i<=m; ++i) { dd[i].k=read(); dd[i].p=read(); } //init inf for(int i=0; i<2005; ++i) for(int j=0; j<=10; ++j) dp[i][j]=inf; for(int i=0; i<=10; ++i) { dp[0][i]=0; for(int j=1; j<=m; ++j) { // LL t=dd[j].p-i; LL t=dd[j].p-i; if(t<=0) continue; for(int pp=t; pp<=2004; ++pp) { dp[pp][i]=min(dp[pp-t][i]+dd[j].k,dp[pp][i]); } } for(int j=2003; j>=0; --j)//!!! { dp[j][i]=min(dp[j][i],dp[j+1][i]); } } int p1=0,p2=0; bool flag=false; LL ret=0; for(int i=1; i<=n; ++i) ret+=dp[king[i].a][king[i].b]; if(ret>=inf) puts("-1"); else printf("%I64d\n",ret); } return 0; }