a,b=input().split(' ')
a,b=int(a),int(b)
c=input().split(' ')
c=list(map(int,c))
gs=0
gc=1
gt=c.pop(0)
for i in c:
# print(i,gs,'g',gt)
if i>=gt+b and gc==1 :#賣出
# print('b')
gs+=i-gt
gt=i
gc=0
elif i<gt-b and gc!=1:
# print('a')
# gs-=i
gt=i
gc=1
print(gs)