#include <bits/stdc++.h>
#define ll long long
using namespace std;
ll rek (ll &minp, ll z, ll n, vector <ll> &d, vector <ll> &p, ll brp, ll prof, ll trnp)
{
    if (z<=0 || brp==n)
    {
        minp=min(minp, brp);
        brp=0;
    }
    else
    {
        rek( minp, z-prof-p[trnp], n, d, p, brp+1, prof+p[trnp], trnp+1);
        rek( minp, z-d[trnp]-prof, n, d, p, brp+1, prof, trnp+1);
    }
    return minp;
}
int main()
{
    ll n, q;
    cin>>n>>q;
    vector <ll> d(n), p(n);
    for (ll i=0; i<n; i++)
    {
        cin>>d[i]>>p[i];
    }
    while (q--)
    {
        ll z, minp=LLONG_MAX;
        cin>>z;
        cout<<rek(minp, z, n, d, p, 0, 0, 0)<<endl;
    }
    return 0;
}