#include #define rep(i, j, k) for(int i = (int) j; i < (int) k; ++i) #define sz(x) ((int) (x).size()) #define ll long long #define mp make_pair #define pii pair #define fi first #define se second #define pb push_back #define inf 0x3f3f3f3f #define INF 0x3f3f3f3f3f3f3f3f #define zero(x) memset((x), (0), sizeof (x)) #define zerox(x, y) memset((x), (y), sizeof (x)) using namespace std; const int N = 100100; const int M = 1010; struct Guai{ int a, b, t; Guai(int a_=0, int b_=0) : a(a_), b(b_) {} bool operator<(const Guai& u) const { return a < u.a || (a == u.a && b < u.b); } bool operator==(const Guai& u) const { return a == u.a && b == u.b; } } shou[N]; struct Gong{ int p, k; Gong(int p_=0, int k_=0) : p(p_), k(k_) {} bool operator < (const Gong& u) const { return p > u.p || (p == u.p && k < u.k); } } ji[M]; int n, m; ll re[M]; int bins(int ps) { int l = 0, r = m, mid; while(l <= r) { mid = (l + r) >> 1; if(ji[mid].p <= ps) l = mid + 1; else r = mid - 1; } return l; } int main() { #ifdef PIT //freopen(".in", "r", stdin); //freopen(".out", "w", stdout); #endif //PIT // ios_base::sync_with_stdio(false); cin.tie(0); while(~scanf("%d %d", &n, &m)) { rep(i, 0, n) scanf("%d %d", &shou[i].a, &shou[i].b), shou[i].t = 1; sort(shou, shou+n); int v = 0; rep(i, 1, n) { if(shou[v] == shou[i]) shou[v].t++; else shou[++v] = shou[i]; } ++v; n = v; v = 0; rep(i, 0, m) scanf("%d %d", &ji[i].k, &ji[i].p); sort(ji, ji+m); rep(i, 1, m) { if(ji[v].k <= ji[i].k) continue; else ji[++v] = ji[i]; } ++v; m = v; reverse(ji, ji+m); ji[m] = {inf, inf}; ll ans = 0LL; int f = 1; rep(q, 0, n) { zerox(re, inf); re[shou[q].a] = 0LL; int u = bins(shou[q].b); if(u >= m) {f = 0; break; } for(int i = shou[q].a; i >= 0; --i) if(re[i] != inf){ for(int j = u; j < m; ++j) { int x = max(0, i-ji[j].p+shou[q].b); re[x] = min(re[x], re[i]+ji[j].k); } } ans += re[0] * shou[q].t; } if(!f) puts("-1"); else printf("%I64d\n", ans); } return 0; }