a,b=map(int,input().split())
c=[int(x) for x in input().split()]
d=0
e=c[0]
f=0
for i in range(1,a):
if f==0:
if e<=c[i]-b:
d=d+c[i]-e
e=c[i]
f=1
else:
if e>=c[i]+b:
print(d)