#include #include #include #include #include #include #include #include #include using namespace std; #define cle(a,v) memset(a,(v),sizeof(a)) #define fo(i,a,b) for(int i=(a);i<=(b);i++) #define fd(i,a,b) for(int i=(a);i>=(b);i--) #define ll long long const int maxn = 100000 + 7, maxm = 1000 + 7; int n, m; int a[maxn], b[maxn], k[maxm], p[maxm], dp[11][maxm]; int main() { //("1.in", "r", stdin); while (~scanf("%d%d", &n, &m)) { int topp = 0, topb = 0, topa = 0; fo(i, 1, n) { scanf("%d%d", &a[i], &b[i]); topb = max(b[i], topb); topa = max(a[i], topa); } fo(i, 1, m) { scanf("%d%d", &k[i], &p[i]); topp = max(p[i], topp); } if (topp <= topb) { puts("-1"); continue; } cle(dp, 0x7f); for (int i = 0; i <= 10; i++) { for (int j = 1; j <= topa; j++) { for (int u = 1; u <= m; u++) { int damage = p[u] - i; if (damage < 0) continue; if (j <= damage) dp[i][j] = min(dp[i][j], k[u]); else { dp[i][j] = min(dp[i][j], dp[i][j - damage] + k[u]); } } } } ll ans = 0; fo(i, 1, n) { ans += dp[b[i]][a[i]]; } printf("%I64d\n", ans); } return 0; }