#include using namespace std; const int INF = 0x3f3f3f3f; int a[100005], b[100005], p[1005], k[1005]; int dp[11][1010]; int main() { int n, m; while(~scanf("%d%d", &n, &m)) { for(int i = 1; i <= n; i++) { scanf("%d%d", &a[i], &b[i]); } for(int i = 1; i <= m; i++) { scanf("%d%d", &k[i], &p[i]); } for(int defence = 0; defence <= 10; defence++) { dp[defence][0] = 0; for(int power = 1; power <= 1000; power++) { dp[defence][power] = INF; } } for(int defence = 0; defence <= 10; defence++) { for(int i = 1; i <= m; i++) { for(int power = 0; power <= 1000; power++) { if(p[i] > defence) { int lost = max(power + defence - p[i], 0); dp[defence][power] = min(dp[defence][power], dp[defence][lost] + k[i]); } } } } int flag = 0; long long int ans = 0; for(int i = 1; i <= n; i++) { if(dp[b[i]][a[i]] == INF) { flag = 1; break; } ans += dp[b[i]][a[i]]; } if(flag) printf("-1\n"); else printf("%lld\n", ans); } return 0; }