import sys input = sys.stdin.readline N,P=map(int,input().split()) A=list(map(int,input().split())) USE=[0]*N for i in range(1,N-1): if A[i-1]<=A[i]<=A[i+1]: USE[i]=1 if A[i-1]>=A[i]>=A[i+1]: USE[i]=1 B=[] for i in range(N): if USE[i]==0: B.append(A[i]) if len(B)>=2 and B[0]>=B[1]: B.pop(0) ANS=0 for i in range(0,len(B),2): ANS+=min(B[i+1]-B[i],P) print(ANS)