# include # include # include # include using namespace std; typedef long long ll; const ll INF = 1e17 + 5; const int maxn = 1e5 + 5; const int maxm = 1e3 + 5; int a[maxn], b[maxn]; int k[maxm], p[maxm]; ll d[66][maxm]; int n, m; //# include //# include //# include //# include //using namespace std; //typedef long long ll; //const int maxn = 1e5 + 5; //int n, m; //int Left[maxn], Right[maxn]; // //int main(void) //{ // int Case = 0; // while (~scanf("%d %d", &n, &m)) { // for (int i = 1; i <= n; ++i) { // Left[i] = i - 1; Right[i] = i + 1; // } // Left[1] = n; Right[n] = 1; // int cnt = 0; // int diyi = 1; // // for (int i = 0; i < m; ++i) { // int idd; scanf("%d", &idd); // if (idd == 1 || idd == 2) { // int x, y; scanf("%d %d", &x, &y); // if ((cnt % 2 == 0 && idd == 1) || (cnt % 2 == 1 && idd == 2)) { // if (Left[x] == y) { // if (y == diyi) diyi = x; // else if (x == diyi) diyi = Right[x]; // int xr = Right[x]; // int yl = Left[y]; // Left[x] = yl; Right[x] = y; // Left[y] = x; Right[y] = xr; // Right[yl] = x; Left[xr] = y; // } else if (Right[x] != y) { // if (x == diyi) diyi = Right[x]; // else if (y == diyi) diyi = x; // int t = Left[y]; // int xl = Left[x], xr = Right[x]; // Right[Left[x]] = Right[x]; // Left[Right[x]] = Left[x]; // Left[x] = t; Right[x] = y; // Right[t] = x; Left[y] = x; // } // } else { // if (Right[x] == y) { // if (y == diyi) diyi = y; // else if (x == diyi) diyi = y; // int xl = Left[x]; // int yr = Right[y]; // Left[x] = y; Right[x] = yr; // Left[y] = xl; Right[y] = x; // Right[xl] = y; Left[yr] = x; // } else if (Left[x] != y) { // if (x == diyi) diyi = Right[x]; // else if (y == diyi) diyi = y; // int t = Right[y]; // int xl = Left[x], xr = Right[x]; // Right[Left[x]] = Right[x]; // Left[Right[x]] = Left[x]; // Left[x] = y; Right[x] = t; // Left[t] = x; Right[y] = x; // } // } // } else if (idd == 3) { // int x, y; scanf("%d %d", &x, &y); // if (x == diyi) diyi = y; // else if (y == diyi) diyi = x; // int xl = Left[x], xr = Right[x]; // int yl = Left[y], yr = Right[y]; // Right[xl] = y; Left[xr] = y; // Right[yl] = x; Left[yr] = x; // Left[x] = yl; Right[x] = yr; // Left[y] = xl; Right[y] = xr; // } else if (idd == 4) ++cnt; // } // // ll ans = 0; // if (cnt % 2 == 0 || n % 2 == 1) { // int k = 0; // for (int i = diyi; !k || i != diyi; i = Right[i]) { // if (k % 2 == 0) ans += (ll)i; // ++k; // } // } else { // int k = 0; // for (int i = diyi; !k || i != diyi; i = Right[i]) { // if (k % 2 == 1) ans += (ll)i; // ++k; // } // } // // printf("Case %d: %lld\n", ++Case, ans); // } // // return 0; //} // ///* //6 4 //1 1 4 //2 3 5 //3 1 6 //4 //6 3 //1 1 4 //2 3 5 //3 1 6 //100000 1 //4 // //2 1 //2 1 2 //*/ int main(void) { while (~scanf("%d %d", &n, &m)) { int t1 = 0, t2 = 0; for (int i = 1; i <= n; ++i) { scanf("%d %d", a + i, b + i); t1 = max(t1, b[i]); t2 = max(t2, a[i]); } for (int i = 1; i <= m; ++i) scanf("%d %d", k + i, p + i); for (int i = 0; i <= t1; ++i) { for (int j = 1; j <= t2; ++j) d[i][j] = INF; d[i][0] = 0; for (int j = 1; j <= m; ++j) { if (p[j] <= i) continue; for (int kk = 1; kk <= 1000; kk++) { int t = max(kk - p[j] + i, 0); d[i][kk] = min(d[i][kk], d[i][t] + k[j]); } } } ll ans = 0; for (int i = 1; i <= n; ++i) { if (d[b[i]][a[i]] == INF) { ans = -1; break; } ans += d[b[i]][a[i]]; } printf("%lld\n", ans); } return 0; }