#include using namespace std; #define ff first #define ss second #define pb push_back #define ll long long #define ull unsigned long long #define min3(a, b, c) min(a, min(b, c)) #define max3(a, b, c) max(a, max(b, c)) #define mst(ss,b) memset(ss,b,sizeof(ss)); #ifdef Cyberdebut #define dbg(x) cerr << #x << " = " << x << endl #else #define dbg(x) #endif typedef pair pii; ll gcd(ll a, ll b){return a ? gcd(b%a,a):b;} ll pow_mod(ll x, ll n, ll mod){ll ret=1LL;while(n){if(n&1)ret=ret*x%mod;x=x*x%mod;n>>=1;}return ret;} const int inf = 0x3f3f3f3f; const ll INF = (1LL<<62)-1; const ll mod = 1e9+7; const int N = 1e5+5; ll dp[1005][15]; int n, m, a[N], b[N], k[N], p[N]; int main(){ while(~scanf("%d%d", &n, &m)){ for(int i=1; i<1005; i++)for(int j=0; j<15; j++)dp[i][j] = INF; for(int j=0; j<15; j++)dp[0][j] = 0; int mxa = 0, mxb = 0; for(int i=1; i<=n; i++)scanf("%d%d", &a[i], &b[i]), mxa = max(mxa, a[i]), mxb = max(mxb, b[i]); for(int i=1; i<=m; i++)scanf("%d%d", &k[i], &p[i]); for(int i=1; i<=mxa; i++){ for(int j=0; j<=mxb; j++){ for(int ki=1; ki<=m; ki++){ if(p[ki] <= j)continue; int del = p[ki]-j; dp[i][j] = min(dp[i][j], dp[max(0, i-del)][j]+k[ki]); } } } ll ans = 0; int fg = 1; for(int i=1; i<=n; i++){ if(dp[a[i]][b[i]] >= INF){ fg = 0; break; } } if(!fg)puts("-1"); else{ for(int i=1; i<=n; i++)ans += dp[a[i]][b[i]]; printf("%lld\n", ans); } } return 0; } // lower_bound() // __builtin_popcount() // ios::sync_with_stdio(false); // freopen("in.txt","r",stdin); // freopen("out.txt","w",stdout); // const double eps=1e-12; // #pragma comment(linker,"/STACK:102400000,102400000")