#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef pair<ll, ll> P;

#define EACH(i,a) for (auto& i : a)
#define FOR(i,a,b) for (ll i = (a); i < (b); ++i)
#define RFOR(i,a,b) for (ll i = (b)-1; i >= (a); --i)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define pb push_back
#define ALL(a) (a).begin(),(a).end()

const ll linf = 1e18;
const ll inf = 1e9;
const double eps = 1e-12;
const double pi = acos(-1);

template<typename T>
istream& operator>>(istream& is, vector<T>& vec) {
    EACH(x,vec)is>>x;
    return is;
}
template<typename T>
ostream& operator<<(ostream& os, vector<T>& vec) {
    REP(i, vec.size()) {
        if(i) os << " ";
        os << vec[i];
    }
    return os;
}

P dp[2][1000001];

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    ll n, p; cin >> n >> p;
    vector<ll> X(n), Y(n);
    REP(i, n) cin >> X[i] >> Y[i];

    fill(dp[0], dp[2], P(-1,0));
    dp[0][0] = P(0, 0);
    REP(i, n) {
        fill(dp[i+1&1], dp[(i+1&1)+1], P(-1,-1));
        REP(j, p+1) {
            if (dp[i&1][j].first < 0) continue;
            // ??±????????????
            dp[i+1&1][j] = max(dp[i+1&1][j], P(dp[i&1][j].first, 0));
            // ??±??????
            ll x = max<ll>(0, X[i] - (-dp[i&1][j].second));
            ll need = max<ll>(0, Y[i] - x);
            if (j+need <= p) {
                ll nj = j+need;
                dp[i+1&1][nj] = max(dp[i+1&1][nj], P(dp[i&1][j].first+1, -need));
            }
        }
    }
    ll ans = 0;
    REP(j, p+1) {
        ans = max<ll>(ans, dp[n&1][j].first);
    }
    cout << ans << endl;
}