#include using namespace std; #define rep(i,a,n) for (int i=a;i=a;i--) #define pb push_back #define mp make_pair #define all(x) (x).begin(),(x).end() #define fi first #define se second #define SZ(x) ((int)(x).size()) typedef vector VI; typedef long long ll; typedef pair PII; typedef double db; mt19937 mrand(random_device{}()); const ll mod=1000000007; int rnd(int x) { return mrand() % x;} ll powmod(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;} ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;} // head const int N = 100010; int a[N], b[N], k[1010], p[1010]; ll f[11][1010]; int main() { int n, m; while(scanf("%d%d", &n, &m)==2) { 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 d=0; d<=10; d++) { for(int h=1; h<=1000; h++) { f[d][h] = 1e18; for(int i=1; i<=m; i++) { if(p[i]<=d) continue; f[d][h] = min(f[d][h], f[d][max(h-p[i]+d, 0)]+k[i]); } } } ll ans = 0; for(int i=1; i<=n; i++) { if(f[b[i]][a[i]]>=1e18) { ans = -1; break; } ans += f[b[i]][a[i]]; } printf("%lld\n", ans); } return 0; }