#include #include #include #include #include #include #include #include #define ll long long using namespace std; const int maxn=500010,inf=2e9; ll n,m,x,y,z,tot; ll a[maxn],b[maxn],K[maxn],p[maxn]; ll ans,f[20][2010]; void read(ll &k) { int f=1;k=0;char c=getchar(); while(c<'0'||c>'9')c=='-'&&(f=-1),c=getchar(); while(c<='9'&&c>='0')k=k*10+c-'0',c=getchar(); k*=f; } int main() { while(scanf("%I64d%I64d",&n,&m)==2) { for(int i=1;i<=n;i++)read(a[i]),read(b[i]); for(int i=1;i<=m;i++)read(K[i]),read(p[i]); memset(f,0x3f,sizeof(f)); for(int i=0;i<=10;i++)f[i][0]=0; for(int k=1;k<=m;k++) for(int i=0;i<=10;i++) { int damage=p[k]-i; for(int j=0;j<=1000;j++) f[i][j]=min(f[i][j],f[i][max(0,j-damage)]+K[k]); } ans=0;bool flag=0; for(int i=1;i<=n;i++) { ans+=f[b[i]][a[i]]; if(f[b[i]][a[i]]>=inf) { flag=1; break; } } printf("%I64d\n",flag?-1:ans); } return 0; }