#include <iostream>
#include<vector>
#include<list>
using namespace std;

int main ()
{
    int n_moves, n_bosses;
    vector<int> normal, poison;
    int mult=0;
    bool normalZero = true;
    bool poisonZero = true;
    cin >> n_moves >> n_bosses;
    for(int movex=0; movex<n_moves; movex++)
    {
        int t1, t2;
        cin >> t1 >> t2;
        normal.push_back(t1);
        poison.push_back(t2);
        if(t1 != 0)
            normalZero = false;
        if(t2 != 0)
            poisonZero = false;

    }
    if(poisonZero)
    {

        for(int boss=0; boss<n_bosses; boss++)
        {
            bool broken = false;
            int k=0;
            int health;
            cin >> health;
            int i=0;
            while(health > 0)
            {
                if(k >= n_moves){
                    cout << -1 << endl;
                    broken = true;
                    break;
                }
                health -= (normal[k]);
                k++;


            }
            if(!broken)
                cout << k << endl;
        }
    }
    else if(normalZero)
    {

        for(int boss=0; boss<n_bosses; boss++)
        {
            bool broken = false;
            int add=0;
            int k=0;
            int health;
            cin >> health;
            while(health > 0)
            {
                if(k >= n_moves){
                    cout << -1 << endl;
                    broken = true;
                    break;
                }
                health -= (poison[k]+add);
                k++;
                add += poison[k];

            }
            if(!broken)
                cout << k << endl;
        }
    }
    else
    {
        long long n_tries=1;
        for(int i=0; i<n_moves; i++)
        {
            n_tries *= 2;
        }

        for(int boss=0; boss<n_bosses; boss++)
        {
            int health;
            cin >> health;


            for(long long t=1; t<=n_tries; t++)
            {
                long long add = 0;
                // at bit 1 data for move 1 is stored.  1 is poison, 0 is normal.
                for(int k=0; k<n_moves; k++)
                {
                    int type = (t/(k))%2;
                    if(type == 1)
                    {
                        add+=poison[k];
                    }
                }
            }

        }
    }
    return 0;
}