#include #include using namespace std; typedef long long LL; #define N 100000 + 5 #define M 1000 + 5 #define INF 1234567890 int n, m, Hp[N], Def[N], Mp[M], Atk[M], Dp[11][M], Min[11][M]; LL ans; int main() { while (scanf("%d%d", &n, &m) == 2) { for (int i = 1; i <= n; i ++) scanf("%d%d", Hp + i, Def + i); for (int i = 1; i <= m; i ++) scanf("%d%d", Mp + i, Atk + i); for (int i = 0; i <= 10; i ++) { Dp[i][0] = 0; for (int j = 1; j < M; j ++) Dp[i][j] = INF; for (int t = 1; t <= m; t ++) { int w = Mp[t], v = Atk[t] - i; if (v <= 0) continue ; for (int j = 0; j < M; j ++) Dp[i][min(j + v, M - 1)] = min(Dp[i][min(j + v, M - 1)], Dp[i][j] + w); } for (int j = M - 1; j; j --) Min[i][j] = min(Dp[i][j], j == M - 1 ? INF : Min[i][j + 1]); } ans = 0; for (int i = 1; ~ans && i <= n; i ++) { ans += Min[Def[i]][Hp[i]]; if (Min[Def[i]][Hp[i]] == INF) ans = -1; } printf("%I64d\n", ans); } return 0; }