#include #define Maxn 100007 #define Maxm 1007 #define inf 1000000007 using namespace std; int read() { int x=0,f=1;char ch=getchar(); while (ch<'0'||ch>'9'){if (ch=='-') f=-1;ch=getchar();} while (ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();} return x*f; } int n,m; int a[Maxn],b[Maxn]; int k[Maxm],p[Maxm]; int f[1007][15]; int main() { while (scanf("%d%d",&n,&m)==2) { 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 r=0;r<=10;r++) { for (int i=1;i<=1000;i++) f[i][r]=inf; f[0][r]=0; for (int i=1;i<=1000;i++) for (int j=1;j<=m;j++) f[i][r]=min(f[i][r],f[max(0,i-max(0,p[j]-r))][r]+k[j]); } long long ans=0; bool check=true; for (int i=1;i<=n;i++) if (f[a[i]][b[i]]>=inf) check=false; else ans+=f[a[i]][b[i]]; if (!check) printf("%d\n",-1); else printf("%lld\n",ans); } return 0; }