class Input_kyopro: def II(self): return int(input()) def MI(self): return map( int,input().split()) def MS(self): return map(str,input().split()) def LMI(self): return list(self.MI()) def LMS(self): return list(self.MS()) def LLI(self,N): return [self.LMI() for _ in range(N)] def LLS(self,N): return [self.LMS() for _ in range(N)] def LS(self,N): return [input() for _ in range(N)] def LSL(self,N): return [list(input()) for _ in range(N)] def LI(self,N): return [self.II() for _ in range(N)] I=Input_kyopro() #入力 N,M=I.MI() A=I.LMI() sa=[] for i in range(1,M): if A[i]-A[i-1]-1!=0: sa.append(A[i]-A[i-1]-1) ans=0 def f(x): if x%2==0: return x if x==1: return 1 return f((x-1)//2)*2 for a in sa: if a%2==0: ans+=a else: if a!=1: ans+=f((a-1)//2)*2 else: ans+=1 print(ans)