#include #define REP(i, a, b) for (int i = a; i <= b; ++i) #define PER(i, a, b) for (int i = a; i >= b; --i) #define RVC(i, S) for (int i = 0; i < S.size(); ++i) #define mp make_pair #define pb push_back #define debug(...) fprintf(stderr, __VA_ARGS__) #define fi first #define se second using namespace std; typedef long long LL; typedef pair pii; typedef vector VI; const int N = 100005; int n, m, ai[N], bi[N], ki[N], pi[N], dp[11][2005]; int main(){ while (scanf("%d%d", &n, &m) == 2){ REP(i, 1, n) scanf("%d%d", &ai[i], &bi[i]); REP(i, 1, m) scanf("%d%d", &ki[i], &pi[i]); REP(t, 0, 10){ memset(dp[t], 0x3f, sizeof dp[t]); dp[t][0] = 0; REP(i, 1, 2000) REP(j, 1, m) if (pi[j] > 0 && i >= pi[j]) dp[t][i] = min(dp[t][i], dp[t][i - pi[j]] + ki[j]); PER(i, 1999, 1) dp[t][i] = min(dp[t][i], dp[t][i + 1]); REP(j, 1, m) --pi[j]; } LL ans = 0; REP(i, 1, n){ if (dp[bi[i]][ai[i]] == 0x3f3f3f3f){ ans = -1; break; } else ans += dp[bi[i]][ai[i]]; } printf("%I64d\n", ans); } return 0; }