#include using namespace std; int n, m, a[100005], b[100005], k[1005], p[1005]; long long f[15][2005], ans; int main() { 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); memset(f, 0x7f7f7f, sizeof f); for (int i = 0; i <= 10; i++) { f[i][0] = 0; for (int j = 0; j <= 1000; j++) for (int l = 1; l <= m; l++) if (p[l] > i) f[i][j + p[l] - i] = min(f[i][j + p[l] - i], f[i][j] + k[l]); for (int j = 2000; j >= 0; j--) f[i][j] = min(f[i][j], f[i][j + 1]); } ans = 0; for (int i = 1; i <= n; i++) if (f[b[i]][a[i]] == f[11][0]) { ans = -1; break; } else ans += f[b[i]][a[i]]; cout << ans << endl; } return 0; }