#include using namespace std; typedef long long LL; const int N = 100005, M = 1005; const LL inf = 1e18; LL dp[11][M]; LL a[N], b[N], k[M], p[M]; int main() { int n, m; while (~scanf("%d%d", &n, &m)) { memset(dp, 0, sizeof(dp)); for (int i = 1; i <= n; ++i) scanf("%I64d%I64d", &a[i], &b[i]); for (int i = 1; i <= m; ++i) scanf("%I64d%I64d", &k[i], &p[i]); for (int i = 0; i <= 10; ++i) for (int j = 1; j <= 1000; ++j) { dp[i][j] = inf; for (int l = 1; l <= m; ++l) { LL t = p[l] - i; if (t <= 0) continue; if (t >= j) dp[i][j] = min(dp[i][j], k[l]); else dp[i][j] = min(dp[i][j], dp[i][j - t] + k[l]); } } LL ans = 0; for (int i = 1; i <= n; ++i) ans += dp[b[i]][a[i]]; if (ans > inf) puts("-1"); else cout << ans << endl; } return 0; }