A plane is flying at a constant height of $h$ meters above the ground surface. Let's consider that it is flying from the point $(-10^9, h)$ to the point $(10^9, h)$ parallel with $Ox$ axis.

A glider is inside the plane, ready to start his flight at any moment (for the sake of simplicity let's consider that he may start only when the plane's coordinates are integers). After jumping from the plane, he will fly in the same direction as the plane, parallel to $Ox$ axis, covering a unit of distance every second. Naturally, he will also descend; thus his second coordinate will decrease by one unit every second.

There are ascending air flows on certain segments, each such segment is characterized by two numbers $x_1$ and $x_2$ ($x_1 < x_2$) representing its endpoints. No two segments share any common points. When the glider is inside one of such segments, he doesn't descend, so his second coordinate stays the same each second. The glider still flies along $Ox$ axis, covering one unit of distance every second.  [Image] If the glider jumps out at $1$, he will stop at $10$. Otherwise, if he jumps out at $2$, he will stop at $12$. 

Determine the maximum distance along $Ox$ axis from the point where the glider's flight starts to the point where his flight ends if the glider can choose any integer coordinate to jump from the plane and start his flight. After touching the ground the glider stops altogether, so he cannot glide through an ascending airflow segment if his second coordinate is $0$.


-----Input-----

The first line contains two integers $n$ and $h$ $(1 \le n \le 2\cdot10^{5}, 1 \le h \le 10^{9})$ — the number of ascending air flow segments and the altitude at which the plane is flying, respectively.

Each of the next $n$ lines contains two integers $x_{i1}$ and $x_{i2}$ $(1 \le x_{i1} < x_{i2} \le 10^{9})$ — the endpoints of the $i$-th ascending air flow segment. No two segments intersect, and they are given in ascending order.


-----Output-----

Print one integer — the maximum distance along $Ox$ axis that the glider can fly from the point where he jumps off the plane to the point where he lands if he can start his flight at any integer coordinate.


-----Examples-----
Input
3 4
2 5
7 9
10 11

Output
10

Input
5 10
5 7
11 12
16 20
25 26
30 33

Output
18

Input
1 1000000000
1 1000000000

Output
1999999999



-----Note-----

In the first example if the glider can jump out at $(2, 4)$, then the landing point is $(12, 0)$, so the distance is $12-2 = 10$.

In the second example the glider can fly from $(16,10)$ to $(34,0)$, and the distance is $34-16=18$.

In the third example the glider can fly from $(-100,1000000000)$ to $(1999999899,0)$, so the distance is $1999999899-(-100)=1999999999$.

Difficulty: interview

Starter code:

Solutions:
from bisect import bisect_left

n, h = map(int, input().split())
x1, x2 = map(int, input().split())
if n == 1:
	print(h + x2 - x1)
else:
	gap_sum = [0]
	airflow_sum = [x2 - x1]
	for _ in range(n - 1):
		oldx1, oldx2 = x1, x2
		x1, x2 = map(int, input().split())
		gap_sum.append(gap_sum[-1] + x1 - oldx2)
		airflow_sum.append(airflow_sum[-1] + x2 - oldx2)

	#print(gap_sum)
	#print(airflow_sum)

	ans = h
	for i in range(n):
		cnt = bisect_left(gap_sum, h + gap_sum[i])
		if i == 0:
			res = airflow_sum[cnt-1] + h - gap_sum[cnt-1]
		else:
			res = airflow_sum[cnt-1] - (airflow_sum[i-1] + gap_sum[i] - gap_sum[i - 1]) + h - (gap_sum[cnt-1] - gap_sum[i])

		if res > ans:
			ans = res
	print(ans)

n, h = map(int, input().split())
a, b = map(int, input().split())
L = [[a, b]]
M = [0]
N = [0]
sum = 0
f = True
for i in range(1, n):
    a, b = map(int, input().split())
    L.append([a, b])
    M.append(a - L[-2][1])
    sum += M[-1]
    if sum >= h and f:
        x = i 
        f = False
    N.append(sum)
if sum < h:
    maximum = L[-1][1] - L[0][0] + h - sum
else:
    #print('x =', x)
    ans = L[x - 1][1] - L[0][0] + h - N[x - 1]
    maximum = ans
    for i in range(1, n):
        while x < n and N[x] - N[i] < h:
            x += 1
        ans = L[x - 1][1] - L[i][0] + h - (N[x - 1] - N[i])
        if ans > maximum:
            maximum = ans
        #print('i =', i, 'x =', x, 'ans =', ans)
print(maximum)

from copy import deepcopy
import itertools
from bisect import bisect_left
from bisect import bisect_right
import math
from collections import deque
from collections import Counter


def read():
    return int(input())


def readmap():
    return list(map(int, input().split()))


def readlist():
    return list(map(int, input().split()))


n, h = readmap()
seg = []
c, b = readmap()
seg.append((0, b-c))
for _ in range(n-1):
    a, b = readmap()
    seg.append((a-c, b-c))

cumu = [0] * n
for i in range(1, n):
    cumu[i] = cumu[i-1] + seg[i][0] - seg[i-1][1]

ans = 0
for i in range(n):
    idx = bisect_left(cumu, h + cumu[i])
    if idx < n:
        can = seg[idx][0] - (cumu[idx] - cumu[i] - h) - seg[i][0]
        ans = max(ans, can)
    else:
        can = seg[-1][1] + (h - cumu[-1] + cumu[i]) - seg[i][0]
        ans = max(ans, can)

print(ans)


import bisect

n, h = [int(e) for e in input().split()]
x = [list(map(int, input().split())) for i in range(n)]
xcum = [x[0][1] - x[0][0]]
for i, e in enumerate(x[1:]):
    xcum.append(xcum[i] + e[1] - e[0])
x_start = [e[0] for e in x]
i = 0
best = -1
cd = x[0][1] - x[0][0]
ch = h
j = i
while i < len(x):
    # print(cd,ch)
    # j = i
    while (j + 1) < len(x) and x[j][1] + ch > x[j + 1][0]:
        cd += x[j + 1][1] - x[j][1]
        ch -= x[j + 1][0] - x[j][1]
        j += 1
    if cd + ch > best:
        # print(i)
        # print(cd + ch)
        best = cd + ch
    if i + 1 < len(x):
        cd -= x[i + 1][0] - x[i][0]
        ch += x[i + 1][0] - x[i][1]
    i += 1
print(best)


import bisect

cl = list(map(int, input().split()))
n, h = cl[0], cl[1]
potok = []
pos = 0
smlist = []
sm = 0
pt = 0
mx = 0
smlist.append(0)
potok.append(0)
for i in range(n):
  s = input().split()
  pt += int(s[1]) - int(s[0])
  potok.append(pt)
  if i!=0:
    sm+=int(s[0])-pos
    smlist.append(sm)
  pos = int(s[1])

for i in range(n):
  pos = bisect.bisect_left(smlist, smlist[i]+h)
  res = potok[pos] - potok[i] +h
  if res>mx:
    mx = res


print(mx)

n, h = map(int, input().split(' '))
x = []
for i in range(n):
    x1, x2 = map(int, input().split(' '))
    x.append([x1, x2])

cur = 1
S = 0
i = 0
res = 0
while cur < n:
    #print()
    while S <= h and i < n - 1:
        i += 1
        S += x[i][0] - x[i - 1][1]
    #print(S, i, res)
    if S > h:
        S -= (x[i][0] - x[i-1][1])
        i -= 1
    #elif i == n - 1:
        #i -= 1
    #print(S, i)
    if S < h:
        res1 = x[i][1] + h - S - x[cur - 1][0]
    else:
        res1 = x[i][0] - x[cur - 1][0]
    res = max(res, res1)
    #print(res)
    S -= (x[cur][0] - x[cur - 1][1])
    cur += 1

res = max(res, x[-1][1] - x[-1][0] + h)
print(res)

n,h=map(int,input().split())
arr=[]
for i in range(n):
    x,y=map(int,input().split())
    arr.append((x,y))
arr.sort()
arr1=[]
for i in range(n-1):
    if(arr[i+1][0]>=arr[i][1]):
        arr1.append(arr[i+1][0]-arr[i][1])
    else:
        arr1.append(0)
fans=0
sumx=0
i=0
j=0
tempans=0
while(i<n and j<n):
    while(j<n-1 and sumx+arr1[j]<h):
        tempans+=arr[j+1][0]-arr[j][0]
        sumx+=arr1[j]
        j+=1
    if(j==n-1):
        tempans+=h-sumx+arr[j][1]-arr[j][0]
        j+=1
        fans=max(tempans,fans)
    else:
        fans=max(tempans+arr[j][1]-arr[j][0]+h-sumx,fans)
        sumx-=arr1[i]
        tempans-=arr[i+1][0]-arr[i][0]
        i+=1
print(fans)

n,h=map(int,input().split())
arr=[]
for i in range(n):
    x,y=map(int,input().split())
    arr.append((x,y))
arr.sort()
arr1=[]
for i in range(n-1):
    if(arr[i+1][0]>=arr[i][1]):
        arr1.append(arr[i+1][0]-arr[i][1])
    else:
        arr1.append(0)
fans=0
sumx=0
i=0
j=0
tempans=0
while(i<n and j<n):
    while(j<n-1 and sumx+arr1[j]<h):
        tempans+=arr[j+1][0]-arr[j][0]
        sumx+=arr1[j]
        j+=1
    if(j==n-1):
        tempans+=h-sumx+arr[j][1]-arr[j][0]
        j+=1
        fans=max(tempans,fans)
    else:
        fans=max(tempans+arr[j][1]-arr[j][0]+h-sumx,fans)
        sumx-=arr1[i]
        tempans-=arr[i+1][0]-arr[i][0]
        i+=1
print(fans)

ans = 0
[n, h] = [int(i) for i in input().split()]
arr = [[int(i) for i in input().split()] for j in range(n)]
l, r, answer, cur = 0, 0, arr[0][1] - arr[0][0], 0
arr += [[10 ** 16, 10**16]]
n += 1
while (r < n - 1):
	for j in range(r + 1, n):
		if cur + arr[j][0] - arr[j - 1][1] < h:
			r += 1
			cur += arr[j][0] - arr[j - 1][1]
			answer += arr[j][1] - arr[j][0]
		else:
			l += 1
			ans = max(ans, answer)
			cur -= arr[l][0] - arr[l - 1][1]
			answer -= arr[l - 1][1] - arr[l - 1][0]
			break

print (ans + h)

# Glider

n, h = map(int, input().split())
s = [0 for i in range(n)]
e = [0 for i in range(n)]

for i in range(n):
    s[i], e[i] = map(int, input().split())

L = 0
R = 0
H = h
M = 0

while L < n:
    while (R < n-1) and (H - (s[R+1] - e[R]) > 0):
        H -= (s[R+1] - e[R])
        R += 1
    
    if e[R] - s[L] + H > M:
        M = e[R] - s[L] + H

    if L < n-1:
        H += s[L+1] - e[L]
    
    L += 1
    
print(M)

n,h = list(map(int,input().split()))

lis = []
for i in range(n):
    x,y = list(map(int,input().split()))
    lis.append((x,y))

ans = lis[0][1] - lis[0][0]
end = 1
have = h
tot = lis[0][1] - lis[0][0]


for x in range(len(lis)):
    if end >= n:
        break
    if x:
        have += lis[x][0] - lis[x-1][1]
        have = min(have,h)
        tot -=  lis[x-1][1] - lis[x-1][0]
        tot = max(tot,lis[x][1] - lis[x][0])
        end = min(n-1,max(end,x+1))

    while have:
        need = lis[end][0] - lis[end-1][1]
        if have > need:
            have -= need
            tot += lis[end][1] - lis[end][0]
        else:
            break

        end += 1
        if end == n:
           break

    ans = max(ans,tot)


print(ans + h)












R = lambda: map(int, input().split())
n, h = R()
ps = []
for _ in range(n):
    l, r = R()
    ps.append([l, r])
l, c, res = 0, 0, 0
for r in range(n):
    c += (ps[r][0] - ps[r - 1][1]) if r > 0 else 0
    while c >= h:
        c -= (ps[l + 1][0] - ps[l][1])
        l += 1
    res = max(res, ps[r][1] - ps[l][0] + h - c)
print(res)

#! /usr/bin/env python
# -*- coding: utf-8 -*-

n, h = list(map(int, input().split()))
xs = [list(map(int, input().split())) for _ in range(n)]

s = [i for i, _ in xs]
t = [i for _, i in xs]

L = 0
R = 0
ans = 0

while L < n:
    while (R < n -1) and (h -(s[R+1]-t[R]))>0:
        h -= s[R+1] - t[R]
        R += 1
    if t[R] - s[L] + h > ans:
        ans = t[R] - s[L] + h
    
    if L < n -1:
        h += s[L+1] - t[L]
    L += 1
print(ans)    


from collections import Counter, defaultdict, deque
read = lambda: list(map(int,input().split()))

n,h = read()
dis = []
for _ in range(n):
    a,b = read()
    dis.append([a,b])

rec = []
for i in range(1, n):
    rec.append(dis[i][0] - dis[i-1][1])
rec.append(float('inf'))

s = 0
left = h
i,j = 0,0
res = 0
vis = [False] * n
while i < n:
    while j < n and left > 0:
        if not vis[j]:
            s += dis[j][1] - dis[j][0]
            vis[j] = True
        if left > rec[j]:
            left -= rec[j]
            s += rec[j]
            j += 1
        else:
            res = max(res, s + left)
            while i < n and  left <= rec[j]:
                s -= dis[i][1] - dis[i][0] + rec[i]
                left += rec[i]
                i += 1
            if i >= n: break

print(res)

# import atexit
# import io
# import sys
#
# _INPUT_LINES = sys.stdin.read().splitlines()
# input = iter(_INPUT_LINES).__next__
# _OUTPUT_BUFFER = io.StringIO()
# sys.stdout = _OUTPUT_BUFFER
#
#
# @atexit.register
# def write():
#     sys.__stdout__.write(_OUTPUT_BUFFER.getvalue())


def main():
    n, h = list(map(int, input().split()))

    trans = []

    for i in range(n):
        a, b = input().split()
        trans.append((int(a), int(b)))

    lIdx = 0
    rIdx = 0

    mx = -9999999
    height = h

    while rIdx + 1 < n:

        while height > 0 and rIdx + 1 < n:
            rIdx += 1
            height -= trans[rIdx][0] - trans[rIdx - 1][1]

        if height == 0:
            mx = max(mx, trans[rIdx][0] - trans[lIdx][0])
        elif height > 0:
            mx = max(mx, trans[rIdx][1] - trans[lIdx][0] + height)
        else:
            mx = max(mx, trans[rIdx][0] + height - trans[lIdx][0])

        lIdx += 1
        height += trans[lIdx][0] - trans[lIdx - 1][1]

    if height == 0:
        mx = max(mx, trans[rIdx][0] - trans[lIdx][0])
    elif height > 0:
        mx = max(mx, trans[rIdx][1] - trans[lIdx][0] + height)
    else:
        mx = max(mx, trans[rIdx][0] + height - trans[lIdx][0])

    print(mx)


def __starting_point():
    main()

__starting_point()

# -*- coding:utf-8 -*-

"""

created by shuangquan.huang at 11/21/18

"""
import bisect

N, H = list(map(int, input().split()))

X = []
s = float('inf')
for i in range(N):
    x1, x2 = list(map(int, input().split()))
    s = min(s, x1)
    X.append((x1, x2))


X = [(x1-s, x2-s) for (x1, x2) in X]
X.sort()


gap = [0] * (N+1)
for i in range(1, N):
    gap[i] = X[i][0] - X[i-1][1]


gpresum = [0] * (N+1)
for i in range(1, N + 1):
    gpresum[i] = gpresum[i-1] + gap[i-1]

gpresum = gpresum[1:]
# print(X)
# print(gap)
# print(gpresum)

ans = 0
for i in range(N):
    # starts from X[i]
    g = gpresum[i]
    j = bisect.bisect_left(gpresum, g + H)
    l = X[j-1][1] - X[i][0] + (H - (gpresum[j-1] - gpresum[i]))
    ans = max(l, ans)

print(ans)











n,h=map(int,input().split())
brr=[0]*n
for i in range(n):
	brr[i]=list(map(int,input().split()))
arr=[0]*(2*n)
for i in range(n):
	arr[2*i]=brr[i][0]
	arr[2*i+1]=brr[i][1]
if n==1:
	print(arr[1]-arr[0]+h)
	return
if h==1:
	dis=0
	for i in range(1,2*n,2):
		dis=max(dis,arr[i]-arr[i-1])
	print(dis+1)
	return

diff=[0]*(n-1)
add=[0]*(n)
for i in range(n-1):
	diff[i]=diff[i-1]+arr[2*i+2]-arr[2*i+1]
	add[i]=add[i-1]+arr[2*i+1]-arr[2*i]
add[n-1]=add[n-2]+arr[2*n-1]-arr[2*n-2]
ans=0
for i in range(0,2*n,2):
	j=i//2
	lo=j
	hi=n-2
	pre=diff[lo-1]
	if lo==0:
		pre=0
	while(lo<=hi):
		mid=(lo+hi)//2
		if diff[mid]-pre<=h:
			lo=mid+1
			if mid==n-2 or diff[mid+1]-pre>h:
				break
		else:
			hi=mid-1
	ext=h-diff[mid]+pre
	if ext!=0:
		ans=max(ans,arr[(mid*2)+3]+ext-arr[i])
	else:
		ans=max(ans,arr[(mid*2)+2]-arr[i])
print(ans)

from collections import *
 
def li():return [int(i) for i in input().rstrip('\n').split(' ')]
def st():return input().rstrip('\n')
def val():return int(input())
 
 
 
n, h = li()
l = []
for i in range(n):l.append(li())
l.sort()
ans = h + l[0][1] - l[0][0]
d = deque()
d.append(l[0])
currrem = h
currdist = l[0][1] - l[0][0]
 
 
for i in range(1,n):
 
    cant = 0
    while currrem <= l[i][0] - l[i-1][1]:
        if cant:break
        a,b = d.popleft()
        if len(d):
            currrem += d[0][0] - b
            currrem = min(currrem,h)
            currdist -= d[0][0] - a
        else:
            if l[i][0] - b <= h:
                d.append(l[i-1])
                break
            cant = 1
            currrem = h
            currdist = 0
    currdist += l[i][1] - l[i][0]
    if len(d):
        currdist += l[i][0] - d[-1][1]
        currrem -= l[i][0] - d[-1][1]
    d.append(l[i])
    ans = max(ans,currdist + currrem)
print(ans)

from collections import *
 
def li():return [int(i) for i in input().rstrip('\n').split(' ')]
def st():return input().rstrip('\n')
def val():return int(input())
 
 
 
n, h = li()
l = []
for i in range(n):l.append(li())
l.sort()
ans = h + l[0][1] - l[0][0]
d = deque()
d.append(l[0])
currrem = h
currdist = l[0][1] - l[0][0]
 
 
for i in range(1,n):
 
    cant = 0
    while currrem <= l[i][0] - l[i-1][1]:
        if cant:break
        a,b = d.popleft()
        if len(d):
            currrem += d[0][0] - b
            currrem = min(currrem,h)
            currdist -= d[0][0] - a
        else:
            if l[i][0] - b <= h:
                d.append(l[i-1])
                break
            cant = 1
            currrem = h
            currdist = 0
    currdist += l[i][1] - l[i][0]
    if len(d):
        currdist += l[i][0] - d[-1][1]
        currrem -= l[i][0] - d[-1][1]
    d.append(l[i])
    ans = max(ans,currdist + currrem)
print(ans)

n,h = list(map(int,input().split()))
lis=[]
for i in range(n):
    a,b = list(map(int,input().split()))
    lis.append([a,b])
lis.sort()
y=h
cur=ans=i=j=0
lis.append([100000000000,100000000000])
#print(lis)
while i<n and j<n:
    dec = lis[i+1][0]-lis[i][1]
    if dec<y:
        cur+=(lis[i+1][0]-lis[i][0])
        ans = max(ans,cur)
        i+=1
        y-=dec
    else:
        aa=lis[i][1]-lis[i][0]
        ans=max(ans,cur+y+aa)
        y-=dec
        while y<=0 and j<n:
            cur-=(lis[j+1][0]-lis[j][0])
            y+=(lis[j+1][0]-lis[j][1])
#            print(cur,lis[j+1][0]-lis[j][0])
            j+=1    
        cur+=(lis[i+1][0]-lis[i][0])
        i+=1
#        print(cur)
#        ans=max(ans,cur)     
#    print(dec,y,cur,ans)
print(ans)            




n, s = map(int, input().split())
mass = list()
arr = list()
past = -1
answer = 0

for i in range(n):
    l, r = map(int, input().split())
    mass.append(r - l)
    if past != -1:
        arr.append(l - past)
    past = r

l2 = 0

local = s
q = mass[0] + s
for j in range(n - 1):
    local -= arr[j]
    if local <= 0:
        l2 = j
        break
    q += mass[j + 1]
answer = q

if local <= 0:
    for i in range(1, n):
        local += arr[i - 1]
        q -= mass[i - 1]
        if local > 0:
            local += arr[l2]
            for j in range(l2, n - 1):
                local -= arr[j]
                if local <= 0:
                    break
                l2 += 1
                q += mass[j + 1]
        if q > answer:
            answer = q
        if local > 0:
            break
        
print(answer)

n, h = [int(i) for i in input().split()]
A = [[int(i) for i in input().split()] for j in range(n)]

r = 0
cur_h = h
ans = 0
for l in range(n):
    while r < n-1 and cur_h > A[r+1][0] - A[r][1]:
        cur_h -= A[r+1][0] - A[r][1]
        r += 1
    ans = max(ans, A[r][1] - A[l][0] + cur_h)
    if l < n-1:
        cur_h += A[l+1][0] - A[l][1]
print(ans)


n, h = [int(i) for i in input().split()]
A = [[int(i) for i in input().split()] for j in range(n)]

r = 0
cur_h = h
ans = 0
for l in range(n):
    while r < n-1 and cur_h > A[r+1][0] - A[r][1]:
        cur_h -= A[r+1][0] - A[r][1]
        r += 1
    ans = max(ans, A[r][1] - A[l][0] + cur_h)
    if l < n-1:
        cur_h += A[l+1][0] - A[l][1]
print(ans)