N,M=map(int,input().split()) A=list(map(int,input().split())) B=[] if A[0]!=1: B.append(A[0]-1) for i in range(M-1): B.append(A[i+1]-A[i]-1) if A[-1]!=N: B.append(N-A[-1]) def calc(n): if n==1: return 0 elif n%2==1: return 2*calc((n-1)//2)+1 else: return 0 ans=sum(b-calc(b) for b in B) print(ans)