N, M = map(int, input().split()) A = list(map(int, input().split())) A = [0]+A+[N+1] M += 2 ans = 0 for i in range(M-1): diff = A[i+1]-A[i]-1 ans += diff if diff%2 == 1: cnt = 0 while diff >= 2 and diff%2 == 1: ans -= 2**cnt diff //= 2 cnt += 1 print(ans)