#include <iostream>
#include <sstream>
#include <string>
#include <list>
#include <vector>
#include <queue>
#include <algorithm>
#include <climits>
#include <cstring>
#include <cmath>
#include <stack>
#include <iomanip>
#include <tuple>
#include <functional>
#include <cfloat>
#include <map>
#include <set>
#include <array>
#include <stdio.h>
#include <string.h>
#include <random>
#include <cassert>
using ll = long long;
using ull = unsigned long long;
using uint = unsigned int;
using namespace std;
#define int long long
#define CONTAINS_VEC(v,n) (find((v).begin(), (v).end(), (n)) != (v).end())
#define SORT(v) sort((v).begin(), (v).end())
#define RSORT(v) sort((v).rbegin(), (v).rend())
#define ARY_SORT(a, size) sort((a), (a)+(size))
#define REMOVE(v,a) (v.erase(remove((v).begin(), (v).end(), (a)), (v).end()))
#define REVERSE(v) (reverse((v).begin(), (v).end()))
#define ARY_REVERSE(v,a) (reverse((v), (v)+(a)))
#define REP(i, n) for (int (i)=0; (i) < (n); (i)++)
#define REPE(i, n) for (int (i)=0; (i) <= (n); (i)++)
#define CONTAINS_MAP(m, a) ((m).find((a)) != m.end())
#define CONTAINS_SET(m, a) ((m).find((a)) != m.end())
void YesNo(bool b) { cout << (b ? "Yes" : "No") << endl; exit(0); }
void Yes() { cout << "Yes" << endl; exit(0); }
void No() { cout << "No" << endl; exit(0); }

int N, X;
int A[101];

int memo[101][101];

int func(int target)
{
	REP(i, 101) REP(j, 101) memo[i][j] = -1;
	memo[0][0] = 0;

	for (int n = 0; n < N; n++)
	{
		for (int i = target; i >= 1; i--)
		{
			for (int j = 0; j < target; j++)
			{
				if (memo[i - 1][j] >= 0)
				{
					int val = memo[i - 1][j] + A[n];
					int new_m = (X - val) % target;
					memo[i][new_m] = max(memo[i][new_m], val);
				}
			}
		}
	}

	if (memo[target][0] < 0) return LLONG_MAX;

	int check = (X - memo[target][0]) % target;
	int wait = (X - memo[target][0]) / target;
	return wait;
}


signed main()
{
	cin >> N >> X;
	REP(i, N) cin >> A[i];

	int ans = LLONG_MAX;
	for (int i = 1; i <= N; i++)
	{
		ans = min(ans, func(i));
	}
	cout << ans << endl;
}


#include <bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define R cin>>
#define ll long long
#define ln cout<<'\n'
#define in(a) insert(a)
#define pb(a) push_back(a)
#define pd(a) printf("%.10f\n",a)
#define mem(a) memset(a,0,sizeof(a))
#define all(c) (c).begin(),(c).end()
#define iter(c) __typeof((c).begin())
#define rrep(i,n) for(ll i=(ll)(n)-1;i>=0;i--)
#define REP(i,m,n) for(ll i=(ll)(m);i<(ll)(n);i++)
#define rep(i,n) REP(i,0,n)
#define tr(it,c) for(iter(c) it=(c).begin();it!=(c).end();it++)
ll check(ll n,ll m,ll x,ll y){return x>=0&&x<n&&y>=0&&y<m;}void pr(){ln;}
template<class A,class...B>void pr(const A &a,const B&...b){cout<<a<<(sizeof...(b)?" ":"");pr(b...);}
template<class A>void PR(A a,ll n){rep(i,n)cout<<(i?" ":"")<<a[i];ln;}
const ll MAX=1e9+7,MAXL=1LL<<61,dx[8]={-1,0,1,0,-1,-1,1,1},dy[8]={0,1,0,-1,-1,1,1,-1};
typedef pair<ll,ll> P;

void Main() {
  ll n,T;
  R n;
  P a[n];
  rep(i,n) cin >> a[i].F >> a[i].S;
  ll Mi=-MAXL,Ma=MAXL;
  {
    rep(i,n) {
      if(a[i].S==1) Mi+=a[i].F;
      if(a[i].S==2) Mi=max(Mi,a[i].F);
      if(a[i].S==3) Mi=min(Mi,a[i].F);
    }
    rep(i,n) {
      if(a[i].S==1) Ma+=a[i].F;
      if(a[i].S==2) Ma=max(Ma,a[i].F);
      if(a[i].S==3) Ma=min(Ma,a[i].F);
    }
  }
  ll l=-MAXL,r=MAXL;
  while(l+1<r) {
    ll m=(l+r)/2;
    ll x=m;
    rep(i,n) {
      if(a[i].S==1) x+=a[i].F;
      if(a[i].S==2) x=max(x,a[i].F);
      if(a[i].S==3) x=min(x,a[i].F);
    }
    if(x<=Mi) l=m;
    else r=m;
  }
  ll z=l;
  R T;
  while(T--) {
    ll x;
    R x;
    if(x<z) pr(Mi);
    else pr(min(Ma,x-z+Mi));
  }
}

int main(){ios::sync_with_stdio(0);cin.tie(0);Main();return 0;}
