#38914: python


111375@goog.ptsh.ntct.edu.tw (陳森凱)


n,d=map(int,input().split())
list1=[int(i) for i in input().split()]
j=1
s=0
x=list1[0]

for i in list1:
    if j==1:
        if i >= x+d:
            s += (i-x)
            j=0
            x=i

    if j==0:
        if i<=x-d:
            j=1
            x=i

print(s)