#include <bits/stdc++.h>
// https://c...content-available-to-author-only...y.com/contest/round-28/task/water-bottles/
using namespace std;
const int N = 1e5 + 3;
int a[N], b[N];
map<long long, vector<int>> on, off;
set<long long> my;
set<int> fillset;
long long vol[N];
int main() {
int i, n;
long long L, other = 0;
scanf("%d %lld", &n ,&L);
for(i = 1; i <= n; i++){
scanf("%d %d", &a[i], &b[i]);
other += a[i];
on[a[i]].push_back(i);
off[b[i]].push_back(i);
my.insert(a[i]);
my.insert(b[i]);
vol[i] = a[i];
}
int cur_bottle = 0;
for(long long w: my){
if(cur_bottle != 0 and cur_bottle * w + other >= L){
//finish it
long long common = (L-other)/cur_bottle;
long long rem = (L-other)%cur_bottle;
for(int pos: fillset){
vol[pos] = common;
if(rem>0) vol[pos]++;
rem--;
L -= vol[pos];
}
break;
}
for(int pos: on[w]){
fillset.insert(pos);
cur_bottle++;
other -= a[pos];
}
for(int pos: off[w]){
vol[pos] = w;
L -= w;
cur_bottle--;
fillset.erase(pos);
}
}
long long mn = 1e10, mx = 0;
for(i = 1; i <= n; i++){
mn = min(mn, vol[i]);
mx = max(mx, vol[i]);
}
printf("%lld\n", mx-mn);
return 0;
}
I2luY2x1ZGUgPGJpdHMvc3RkYysrLmg+Ci8vIGh0dHBzOi8vYy4uLmNvbnRlbnQtYXZhaWxhYmxlLXRvLWF1dGhvci1vbmx5Li4ueS5jb20vY29udGVzdC9yb3VuZC0yOC90YXNrL3dhdGVyLWJvdHRsZXMvCnVzaW5nIG5hbWVzcGFjZSBzdGQ7CmNvbnN0IGludCBOID0gMWU1ICsgMzsKaW50IGFbTl0sIGJbTl07Cm1hcDxsb25nIGxvbmcsIHZlY3RvcjxpbnQ+PiBvbiwgb2ZmOwpzZXQ8bG9uZyBsb25nPiBteTsKc2V0PGludD4gZmlsbHNldDsKbG9uZyBsb25nIHZvbFtOXTsKaW50IG1haW4oKSB7CglpbnQgaSwgbjsKCWxvbmcgbG9uZyBMLCBvdGhlciA9IDA7CglzY2FuZigiJWQgJW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