''' 8の時 4 1 3 oooo-o*o 3 1 4 o*o-oooo ''' N,M=map(int,input().split()) A=list(map(int,input().split())) ans=0 for i in range(1,M): tmp=A[i]-A[i-1]-1 count=1 while tmp!=1 and tmp%2!=0: tmp//=2 count*=2 ans+=count*tmp print(ans)