#include <bits/stdc++.h>

using namespace std;

using i64 = int64_t;

const i64 INF = 1e18 + 7;
const i64 MOD = 1e9 + 7;


signed main(){
    i64 n, m;
    cin >> m >> n;
    vector<i64> cost(m), power(m);
    for(i64 i = 0; i < m; ++i)
        cin >> cost[i] >> power[i];

    vector<i64> time(n), required(n);
    for(i64 i = 0; i < n; ++i)
        cin >> time[i] >> required[i];

    vector<i64> cost_sum(m + 1, 0), power_sum(m + 1, 0), power_diff_sum(m, 0);
    for(i64 i = 0; i < m; ++i){
        cost_sum[i + 1] = cost_sum[i] + cost[i];
        power_sum[i + 1] = power_sum[i] + power[i];
        if(i != m - 1)
            power_diff_sum[i + 1] = power_diff_sum[i] + abs(power[i + 1] - power[i]);
    }

    vector<vector<i64>> abs_sums(m + 1, vector<i64>(m + 1, 0));
    for(i64 j = 0; j <= m; ++j){
        for(i64 k = 0; k <= m; ++k){
            if(k - j >= 2)
                abs_sums[j][k] = abs(power[k - 1] - power[k - 2]);
        }
    }

    vector<vector<i64>> dp(n + 1, vector<i64>(m + 1, -INF));
    dp[0][0] = 0;
    i64 req = 0;
    for(i64 i = 0; i < n; ++i){
        req = max(req, required[i]);
        // for(i64 j = 0; j <= m; ++j){

            i64 now_power = -INF; // dp[i][j];
            i64 now_power_2 = -INF;
            i64 now_power_3 = -INF;
            for(i64 k = 0; k <= m && time[i] >= cost_sum[k]; ++k){
                now_power_3 = dp[i][k];
                if(k){
                    now_power += power[k - 1];
                    now_power_2 += power[k - 1];
                }
                if(k >= 2){
                    now_power += abs(power[k - 1] - power[k - 2]);
                }
                /*
                if(j != k)
                    now_power += power[k - 1];
                if(k - j >= 2)
                    now_power += abs_sums[j][k];
                */
                i64 max_power = max({now_power, now_power_2, now_power_3});
                if(max_power >= req)
                    dp[i + 1][k] = max(dp[i + 1][k], max_power);


                now_power = max(now_power, now_power_2);
                now_power_2 = now_power_3;
                now_power_3 = -INF;
            }
        // }
    }

    for(i64 i = 0; i <= m; ++i){
        i64 money = time.back() - cost_sum[i];
        if(dp.back()[i] >= req){
            cout << money << endl;
            return 0;
        }
    }
    cout << -1 << endl;
}

